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_dirs
will be placed on the stack when the shell startsAll directories which are visited by
cd
are pushed on the dir stack as wellIn this example
cd
is re-configured as a zsh functioncd foo
will:execute
builtin cd
cmd.When it fails it executes
cf foo
instead, andwill try to find a matching foo dir in
dirs -v
withgrep -i foo
(case independent).If it finds one, it will
cd
into 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¶
setops
to list all set optionsemulate -lLR zsh
to list all avaiable options