Skip to content

Instantly share code, notes, and snippets.

@ttscoff
Last active June 20, 2016 10:07
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ttscoff/2251ec8d7f477f7d3fd0 to your computer and use it in GitHub Desktop.
Save ttscoff/2251ec8d7f477f7d3fd0 to your computer and use it in GitHub Desktop.
up: Quickly cd up a directory tree
# inspired by `bd`: https://github.com/vigneshwaranr/bd
function _up() {
local rx updir
rx=$(ruby -e "print '$1'.gsub(/\s+/,'').split('').join('.*?')")
updir=`echo $PWD | ruby -e "print STDIN.read.sub(/(.*\/${rx}[^\/]*\/).*/i,'\1')"`
echo -n "$updir"
}
function up() {
if [ $# -eq 0 ]; then
echo "up: traverses up the current working directory to first match and cds to it"
echo "You need an argument"
else
cd $(_up "$@")
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment