Created
April 27, 2011 00:36
-
-
Save markhibberd/943494 to your computer and use it in GitHub Desktop.
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
findbase() { | |
search="$1" | |
current="$2" | |
base=`basename $current` | |
case "$base" in | |
"."|""|"/") | |
return 1 | |
;; | |
"$search") | |
echo $current | |
return 0 | |
;; | |
*) | |
findbase "$search" "`dirname $current`" | |
;; | |
esac | |
} | |
cdup() { | |
if [ $# -ne 1 ]; then | |
echo "cd up to an ancestor folder of the specified name" | |
echo "usage: `basename $0` dir" | |
return 1 | |
fi | |
target="$1" | |
directory=`pwd` | |
result=`findbase $target $directory` | |
if [ $? -ne 0 ]; then | |
echo "Could not find ancestor folder [$target]." | |
return 1 | |
fi | |
echo $result | |
cd $result | |
return 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment