Skip to content
Tom edited this page Aug 8, 2019 · 1 revision

Welcome to the zsh-load wiki!

This is a small framework on top of oh-my-zsh. It makes it possible to abstract your .zshrc into multiple files.

Setup this by simply adding the following to your .zshrc file

export ZSH_LOAD=$ZSH/load
export ZSH_PRELOAD=$ZSH_LOAD/preload

function load() {
  for script in $(ls $1)
  do
    LOC=$1"/"$script
    if [ -f $LOC ]; then
      #only load a file that is an sh extentions
      if [[ $LOC == *.sh ]]; then
        . $LOC
      fi
    fi
  done
}

#load every script that needs to load before the oh my zsh framework
load $ZSH_PRELOAD

#load the oh my zsh framework
source $ZSH/oh-my-zsh.sh

#load every other script after the oh my zsh framework (thus we can use its functions)
load $ZSH_LOAD

This framework can load before and after the .oh-my-zsh framework is loaded.

If you want to load something before the framework (usually to alter the oh-my-zsh framework behaviour) add your script to the $ZSH_PRELOAD directory Anything else you want to do when starting up a shell should be put inside the $ZSH_LOAD directory

Example

This for instance needs to be in the $ZSH_PRELOAD directory

#!/bin/bash

#plugins used by ZSH
plugins=(
  zsh-autosuggestions # give autocompletion example when typing a command
  zsh-syntax-highlighting #colorize the command you enter in your terminal
  zsh-completions
)

The reason they need to be loaded before oh-my-zsh is because it uses the plugins array to load in these plugins

An example for $ZSH_LOAD would be the following

#!/bin/bash
alias password='echo $(head -c 100 /dev/urandom | base64 | head -c 12)'
alias neoshot="neofetch | sed -r 's:Public IP.*[0-9a-f]{2}:Public IP\: Blurred for screenshot purpose:'"

This enables aliases you use often inside ever shell.

Clone this wiki locally