Last active
December 10, 2015 16:18
-
-
Save zmughal/4460138 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
alias ..='up' | |
# <http://orangesplotch.com/bash-going-up/> | |
# Go up directory tree X number of directories | |
function up() { | |
COUNTER="$@"; | |
END_OLDPWD="$PWD" | |
# default $COUNTER to 1 if it isn't already set | |
if [[ -z $COUNTER ]]; then | |
COUNTER=1 | |
fi | |
# make sure $COUNTER is a number | |
if [ $COUNTER -eq $COUNTER 2> /dev/null ]; then | |
nwd="`pwd`" # Set new working directory (nwd) to current directory | |
# Loop $nwd up directory tree one at a time | |
until [[ $COUNTER -lt 1 ]]; do | |
nwd=`dirname "$nwd"` | |
let COUNTER-=1 | |
done | |
cd "$nwd" # change directories to the new working directory | |
else | |
# print usage and return error | |
echo "usage: up [NUMBER]" | |
return 1 | |
fi | |
OLDPWD="$END_OLDPWD" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment