Last active
June 15, 2017 07:53
-
-
Save nicksantamaria/76d94af7258150a3d6df610669515836 to your computer and use it in GitHub Desktop.
Script to update your GOPATH when working with multiple workspaces.
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
#!/usr/bin/env bash | |
set -euo pipefail | |
IFS=$'\n\t' | |
#/ Usage: source ./goenv.sh | |
#/ Description: Adjusts GOPATH environment variable to support multiple workspaces. | |
#/ Inspired by https://github.com/dgnorton/goenv/blob/master/goenv.sh | |
#/ Options: | |
#/ --help: Display this help message | |
usage() { grep '^#/' "$0" | cut -c4- ; exit 0 ; } | |
expr "$*" : ".*--help" > /dev/null && usage | |
DEFAULT_GOPATH="${HOME}/go" | |
c=$(pwd)/dummy | |
while : | |
do | |
d=$(basename $(dirname $c)) | |
if [ "$d" == "/" ]; then | |
echo not a valid GOPATH | |
break | |
elif [ "$d" == "workspace" ]; then | |
WORKSPACE=$(dirname $c) | |
export GOPATH="${WORKSPACE}:${DEFAULT_GOPATH}" | |
echo "GOPATH set to ${GOPATH}" | |
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