Created
December 13, 2011 21:57
-
-
Save ieure/1474072 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
function up () | |
{ | |
if [ "$1" != "" -a "$2" != "" ]; then | |
local DIR=$1 | |
local TARGET=$2 | |
elif [ "$1" ]; then | |
local DIR=$PWD | |
local TARGET=$1 | |
fi | |
while [ ! -e $DIR/$TARGET -a $DIR != "/" ]; do | |
DIR=$(dirname $DIR) | |
done | |
test $DIR != "/" && echo $DIR/$TARGET | |
} | |
function catup () | |
{ | |
TARGET=`up $1` | |
test "$TARGET" != "" && cat $TARGET | |
} | |
function lsup () | |
{ | |
TARGET=`up $*` | |
test "$TARGET" != "" && ls -l $TARGET | |
} | |
function cdup () | |
{ | |
if [ "$1" != "" ]; then | |
TARGET=$* | |
else | |
TARGET=.git | |
fi | |
TARGET=`up $TARGET` | |
test "$TARGET" != "" && cd $(dirname $TARGET) | |
} |
Because there is no advantage unless changing to .git
dirs is your only use. If that is the case, the code is much simpler; you could just do:
alias cdup=cd `git rev-parse --show-toplevel`
For any other use-case it is significantly worse, as the code becomes more complex and dependent on an external tool which is often not installed by default.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I can see the non-git use case being useful, but for the git case, why not just do cd
git rev-parse --show-toplevel
?