Last active
December 17, 2015 21:58
-
-
Save tag-dmasse/5678140 to your computer and use it in GitHub Desktop.
Change directory upwards to the first directory containing a .git directory. Helpful in quickly getting to the root of a git project.
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
cdg () { | |
CD="`~/bin/cdg.sh`" | |
cd $CD | |
} |
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
#!/bin/bash | |
PATH="./" | |
LASTPATH="$PATH" | |
while [ 1 -eq 1 ] | |
do | |
if [ `/usr/bin/find "$PATH" -maxdepth 1 -type d -name ".git" | /usr/bin/wc -l` = "1" ] | |
then | |
echo "$PATH" | |
exit 0 | |
else | |
LASTPATH="$PATH" | |
PATH="$PATH../" | |
# Exit if this is the highest directory available -- no .git found | |
if [ `/bin/readlink -f "$PATH"` = `/bin/readlink -f "$LASTPATH"` ] | |
then | |
echo "./" | |
exit 1 | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment