My .zshrc became is too long to maintain it easily. I’ve decided to take the idea behind apache configuration in Debian and to split the .zshrc parts into easily maintainable subscripts. I have no idea if ZSH supports this in some vim-like form of .zsh/plugins, so I did it manually.

Preparation

The first step is to create the following directories

$ mkdir -p ~/bin/zsh-modules-available
$ mkdir -p ~/bin/zsh-modules-enabled

and to make a backup of old .zshrc like this

mv ~/.zshrc ~/.zshrc.backup

Setup

Open the ~/.zshrc file with your favourite editor, and copy the following into it (replacing the old code):

# Lines configured by zsh-newuser-install
source /etc/profile

for file in ~/bin/zsh-modules-enabled/*; do
    source $file
done

Splitting up

Now, open .zshrc.backup file we created earlier and split it into modules which you’ll save into ~/bin/zsh-modules-available. You can split it up any way you want. For example, one of the modules could be the following:

# Module: Aliases
# path: bin/zsh-modules-available/aliases
alias :q=exit
alias la='ls -A --color'
alias rm='rm -i'
alias f='find -name '
alias df='df -h'
alias gg='ack-grep'

Enabling modules

The last step is to choose which modules you want enabled, and to specify the order of execution by prefixing the names with a number from 00 to 99.

Go to the ~/bin/zsh-modules-enabled and do the following for the modules you want to enable:

ln -s ../zsh-modules-available/module-name ./xx_module-name

That’s all folks

So, you have a easily maintainable ZSH module system - it is easy to add a new one, to delete an old one, easy to switch them off or on… You could even create functions such as zsh_module_enable/disbable, but I’m too lazy for that. (aka, if you do, please post them in the comments section and I’ll add them to the post.

Cheerio!


You can support my work on , or you can get my book Functional Programming in C++ at if you're into that sort of thing.