Skip to content

Instantly share code, notes, and snippets.

@ttscoff
Last active June 20, 2016 10:07
Show Gist options
  • 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