You are using an obsolete web browser, or you have the page styles (CSS) disabled. You'll be able to access this site, but only a visually simplified version.

ZSH: Organize your .zshrc (should work for BASH as well)

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!

Share and Enjoy:
  • FSDaily
  • Slashdot
  • Digg
  • del.icio.us
  • Identi.ca
  • Twitter
  • Technorati
  • Reddit
  • LinkedIn
  • Netvibes
  • StumbleUpon
  • Facebook
  • Add to favorites
  • email

5 Comments

  1. [...] You can copy the script to your .zshrc, or create a zsh module as described in my previous post [...]

    Pingback by Ivan Čukić » ZSH: bookmarks for cd (change directory) with completion — 29 January 2010 @ 22:34 Reply to this comment

  2. You might also find Martin Krafft’s layout interesting:

    http://git.madduck.net/v/etc/zsh.git?a=tree

    Comment by John — 30 January 2010 @ 21:13 Reply to this comment

  3. [...] ZSH: Organize your .zshrc (should work for BASH as well) [...]

    Pingback by Links 1/2/2010: German Migrations to Free Software, New Debian | Boycott Novell — 2 February 2010 @ 05:32 Reply to this comment

  4. Split configuration is great for daemons, because those read their configuration infrequently.

    But shells… I open new ones all the time. Does doing this make things noticeably slower?

    What about in high-load situations? For example, I needed to turn bash-completion with bash on one of my highly loaded servers, as logging in would sometimes take several seconds.

    Comment by Samat Jain — 8 February 2010 @ 07:15 Reply to this comment

  5. @Samat Jain: TBH, I haven’t even thought about speed – it doesn’t seem to load things slower than usual. I’d guess that loading/setting the options for completion, … takes a lot more time than a simple ‘source ‘.

    Comment by Ivan Čukić — 8 February 2010 @ 08:28 Reply to this comment

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.