Another zsh-related post. This one is about defining a function that will allow you to define aliases for directories so that you don’t need to type something like ‘cd /this/is/a/very/long/path/in/the/filesystem’, but only ‘cdb some-alias’ (cdb - Change Directory with Bookmarks)

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

# Module: Change directory with bookmarks
# path: bin/zsh-modules-available/cdbookmarks

function cdb_edit() {
  vim ~/.cdbookmarks
}

function cdb() {
  NewDir=`egrep "^$1<TAB_KEY>" ~/.cdbookmarks \
     | sed 's/^.*<TAB_KEY>//'`;
  echo cd $NewDir
  cd $NewDir
}

function _cdb() {
  reply=(`cat ~/.cdbookmarks | sed 's/<TAB_KEY>.*$//'`);
}

compctl -K _cdb cdb

That’s it. To define the bookmarks, create a file named ~/.cdbookmarks and the bookmarks in the following format:

(no spaces) Cheerio!