Created
March 3, 2017 00:51
-
-
Save mwarzynski/ec53b88137560693de5aaf014aebdcd5 to your computer and use it in GitHub Desktop.
Automatically setting Golang envs.
This file contains 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
#!/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