Skip to content

Instantly share code, notes, and snippets.

@ronin13
Created October 15, 2010 15:21
Show Gist options
  • Save ronin13/628368 to your computer and use it in GitHub Desktop.
Save ronin13/628368 to your computer and use it in GitHub Desktop.
cd () {
emulate -LR zsh
if [[ $# -ge 3 ]]; then
echo cd: too many arguments >&2
return 1
elif [[ $# -eq 2 ]]; then
## builtin cd $1 $2
local newdir=${(S)PWD//$1/$2}
echo $newdir
builtin cd $newdir
elif [[ $# -eq 1 ]]; then
if [[ ! -d $1 && -d $1:h ]]; then
echo $1:h
builtin cd $1:h
else
builtin cd $1
fi
else
builtin cd
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment