Skip to content

Instantly share code, notes, and snippets.

@rupa
Created June 11, 2009 00:31
Show Gist options
  • Save rupa/127617 to your computer and use it in GitHub Desktop.
Save rupa/127617 to your computer and use it in GitHub Desktop.
# change part of pwd path, and cd to it
# example:
# /usr/lib/foo$ cx lib src
# /usr/src/foo$
# slashes need double escaping: \\/
# surprisingly, most everything else doesn't
cx() {
local cd="$PWD"
while [ $1 ]; do
cd="$(echo $cd | sed "s/$1/$2/")"
shift; shift
done
shopt -s cdspell
cd $cd
shopt -u cdspell
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment