Skip to content

Instantly share code, notes, and snippets.

@disq
Last active January 2, 2017 07:46
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save disq/42459b522836b25f30469b3acb5500bf to your computer and use it in GitHub Desktop.
Save disq/42459b522836b25f30469b3acb5500bf to your computer and use it in GitHub Desktop.
gcd: cd in GOPATH
# 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