Last active
January 2, 2017 07:46
-
-
Save disq/42459b522836b25f30469b3acb5500bf to your computer and use it in GitHub Desktop.
gcd: cd in GOPATH
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
# Put this in ~/.bash_profile | |
# https://gist.github.com/disq/42459b522836b25f30469b3acb5500bf | |
gcd() { | |
if [[ "$1" == "" || "$2" != "" ]]; then | |
echo "Usage: gcd <dir in gopath>" | |
return 1 | |
fi | |
FINDIN=${GOPATH}/src | |
# Exact match | |
D=$(find ${FINDIN} -type d -name "$1" -not -path '*/vendor/*' -print -quit) | |
if [[ "$D" == "" ]]; then | |
# Wild match | |
D=$(find ${FINDIN} -type d -name "*$1*" -not -path '*/vendor/*' -print -quit) | |
fi | |
if [[ "$D" == "" ]]; then | |
# Path match | |
D=$(find ${FINDIN} -type d -path "*$1*" -not -path '*/vendor/*' -print -quit) | |
fi | |
if [[ "$D" == "" ]]; then | |
echo "gcd: Not found in ${FINDIN}" | |
return 1 | |
fi | |
echo $D | |
cd "$D" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment