Skip to content

Instantly share code, notes, and snippets.

@mwarzynski
Created March 3, 2017 00:51
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 mwarzynski/ec53b88137560693de5aaf014aebdcd5 to your computer and use it in GitHub Desktop.
Save mwarzynski/ec53b88137560693de5aaf014aebdcd5 to your computer and use it in GitHub Desktop.
Automatically setting Golang envs.
#!/bin/bash
DIRECTORY=${PWD}
export GOROOT=/usr/local/go
export GOPATH=$(echo $DIRECTORY | awk -F'/src/' '{print $1}')
CHANGED=0
if [[ $PATH != *$GOROOT* ]]; then
echo "adding GOROOT/bin to PATH"
export PATH=$PATH:$GOROOT/bin
export PATH_WITHOUT_GOPATH=$PATH
CHANGED=1
fi
if [[ $PATH != *$GOPATH* ]]; then
echo "adding GOPATH/bin to previously saved PATH"
export PATH=$PATH_WITHOUT_GOPATH:$GOPATH/bin
CHANGED=1
fi
export GOBIN=$GOPATH/bin
if [[ $CHANGED -eq 1 ]]; then
echo ""
echo "GOROOT: " $GOROOT
echo "GOPATH: " $GOPATH
echo "PATH: " $PATH
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment