Created
July 17, 2014 20:37
-
-
Save brock/e0fdc05bd8d49fc234c7 to your computer and use it in GitHub Desktop.
GROOT - go to the "git root"
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
#!/bin/bash | |
# GROOT! v 1.0.0 | |
# Install in your dotfiles, .bashrc, .zshrc or similar | |
# No more cd ../../../../.. to get to the root of a git project | |
# Running the command "groot" will look for the closest .git directory and take you there. | |
# Note that it doesn't traverse up the tree, it takes you directly to the directory with a .git in it... | |
# ...so the command `cd -` takes you back to where you were. | |
# Works with *some* submodules (depending on how your submodule was setup - as a file or a dir) | |
# If you are using submodules, you should be able to figure out how to modify this. | |
# If you are using submodules, but you CAN'T figure out how to modify this, go here: http://goo.gl/nI0zLc | |
function groot() { | |
GROOTDIR=$PWD | |
FOUND=$(find $GROOTDIR -type d -name ".git") | |
while [ -z "$FOUND" ] | |
do | |
GROOTDIR=$(dirname $GROOTDIR) | |
FOUND=$(find $GROOTDIR -type d -name ".git") | |
done | |
cd $GROOTDIR | |
unset GROOTDIR | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment