Created
May 24, 2019 19:59
-
-
Save cxw42/2c8e86132a7d7d0d2ee6121c5cb19a38 to your computer and use it in GitHub Desktop.
cd to the root of a git repo, even from .git or from submodules (bash)
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
# Edit as noted below, then source this from your .bashrc, or paste it in there. Then | |
# cdgr | |
# will move you to the root of the current git repo (if any). | |
# If you are in a submodule, it will move you to the top of the containing repo. | |
# Edits: | |
# - If you are not on Cygwin, remove line 16 | |
# - If you are on Cygwin, change YOUR_USERNAME on line 16 to ... your username ;) . | |
# This is to map from /cygdrive paths back to Cygwin-native paths. | |
function cdgr_munge_dirs() { | |
sed ' | |
s#^true$#'"${PWD%%/.git*}"'# ; | |
1 { | |
s#/cygdrive/c/Users/YOUR_USERNAME#'"$HOME"'#i ; | |
q | |
}' | |
} | |
alias cdgr='cd "$(git rev-parse --show-superproject-working-tree --show-toplevel --is-inside-git-dir | cdgr_munge_dirs)"' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment