Tips and Tricks¶
zsh shell¶
Fast cd¶
To cd seaming less into directories in a zsh:
Example¶
$ pwd
~
$ cf foo
$ pwd
~/path/to/working/dir/foo
$
Explanation¶
Dirs in the file
~/.zshrc_dirswill be placed on the stack when the shell startsAll directories which are visited by
cdare pushed on the dir stack as wellIn this example
cdis re-configured as a zsh functioncd foowill:execute
builtin cdcmd.When it fails it executes
cf fooinstead, andwill try to find a matching foo dir in
dirs -vwithgrep -i foo(case independent).If it finds one, it will
cdinto it.If not it will print a final error message and exit.
Configuration¶
Create ~/.zshrc_dirs:
~/path/to/working/dir/foo
~/path/to/other/dir/bar
Add to ~/.zshrc:
setopt autopushd pushdignoredups pushdminus
alias d='dirs -v'
dirs $(< ~/.zshrc_dirs)
cd() {
builtin cd $1 2> /dev/null || cf $1
}
cf() {
new=$(dirs -v | grep -i $1 | head -1 | cut -f1)
if [[ -n $new ]] ; then
cd -$new
else
echo "cd error: dir $1 not found..."
fi
}
zsh options¶
setopsto list all set optionsemulate -lLR zshto list all avaiable options