One of the most useful features in Zsh is its support for user-defined widgets. These two commands will greatly speed up your directory navigation in Zsh:

setopt autopushd

go-up () {
cd ..
zle reset-prompt
}; zle -N go-up

go-to-previous () {
popd
zle reset-prompt
}; zle -N go-to-previous

bindkey '^[u' go-up
bindkey '^[p' go-to-previous

Now you can go up one level with Alt-U and go backwards in history with Alt-P. Also, this won't clutter your terminal with "cd .." lines, as the prompt line gets automagically updated. Similarly, you can add bookmark-like functionality with something like this:

typeset -Ag bookmark

bookmark[1]="$HOME/work/project"
bookmark[2]="$HOME/work/project/src/foo/bar"
bookmark[3]="$HOME/work/project/test/foo/bar"
bookmark[4]="..."
bookmark[5]="..."
bookmark[6]="..."
bookmark[7]="..."
bookmark[8]="..."
bookmark[9]="..."
bookmark[0]="..."

go-to-bookmark () {
cd $bookmark[$KEYS[-1]]
zle reset-prompt
}; zle -N go-to-bookmark

bindkey '^[0' go-to-bookmark
bindkey '^[1' go-to-bookmark
bindkey '^[2' go-to-bookmark
bindkey '^[3' go-to-bookmark
bindkey '^[4' go-to-bookmark
bindkey '^[5' go-to-bookmark
bindkey '^[6' go-to-bookmark
bindkey '^[7' go-to-bookmark
bindkey '^[8' go-to-bookmark
bindkey '^[9' go-to-bookmark

Have fun!

  • Facebook
  • Twitter
  • Digg
  • Reddit
  • del.icio.us
  • StumbleUpon

No related posts.