Skip to content

Instantly share code, notes, and snippets.

@dgnorton
Created November 22, 2017 15:11
Show Gist options
  • Save dgnorton/22e26d5cd3e181b0eafa26bccb942bd5 to your computer and use it in GitHub Desktop.
Save dgnorton/22e26d5cd3e181b0eafa26bccb942bd5 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Source this script from within any directory within a valid potential
# GOPATH and it will set it. It looks for the first parent directory
# named "go" or "Go" and sets GOPATH to it.
c=$(pwd)/dummy
while :
do
d=$(basename $(dirname $c))
if [ "$d" == "/" ]; then
echo not a valid GOPATH
break
elif [ "$d" == "go" ] || [ "$d" == "Go" ]; then
export GOPATH=$(dirname $c)
export PATH=$PATH:$GOPATH/bin
echo GOPATH set to $GOPATH
echo Appended $GOPATH/bin to PATH
git status | grep "On branch"
break
else
c=$(dirname $c)
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment