Skip to content

Instantly share code, notes, and snippets.

@ieure
Created December 13, 2011 21:57
Show Gist options
  • Save ieure/1474072 to your computer and use it in GitHub Desktop.
Save ieure/1474072 to your computer and use it in GitHub Desktop.
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)
}
@ieure
Copy link
Author

ieure commented Dec 13, 2011

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