Skip to content

Instantly share code, notes, and snippets.

@nicksantamaria
Last active June 15, 2017 07:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicksantamaria/76d94af7258150a3d6df610669515836 to your computer and use it in GitHub Desktop.
Save nicksantamaria/76d94af7258150a3d6df610669515836 to your computer and use it in GitHub Desktop.
Script to update your GOPATH when working with multiple workspaces.
#!/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