Last active
June 20, 2016 10:07
-
-
Save ttscoff/2251ec8d7f477f7d3fd0 to your computer and use it in GitHub Desktop.
up: Quickly cd up a directory tree
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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