Skip to content

Instantly share code, notes, and snippets.

@marcinwyszynski
Created April 12, 2012 13:57
Show Gist options
  • Save marcinwyszynski/2367469 to your computer and use it in GitHub Desktop.
Save marcinwyszynski/2367469 to your computer and use it in GitHub Desktop.
Shell function to skip to a parent directory
# Go upwards the path until the basename is equal
# to your argument.
function cdp {
CURRENT=$(basename $PWD)
until [ $CURRENT == "$*" ]; do
cd ..
CURRENT=$(basename $PWD)
done
}
_cdp() {
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $(compgen -W "${PWD//\// }" $cur) )
}
complete -F _cdp cdp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment