Skip to content

Instantly share code, notes, and snippets.

@disq

disq/gcd.sh

Last active Jan 2, 2017
Embed
What would you like to do?
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