-
-
Save mangalaman93/ab970fdcbc778ae16100 to your computer and use it in GitHub Desktop.
virtual enviornment for golang
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 | |
if [[ $0 != "/bin/bash" ]]; then | |
echo "Error: source the script!" | |
exit 1 | |
fi | |
if [[ ! -d $(pwd)/go/bin ]]; then | |
echo "Error: go installtion not found in the current directory!" | |
return | |
fi | |
if [[ -f ./deactivate ]]; then | |
echo "Error: already in a vritual enviornment!" | |
echo "delete ./deactivate and run again if you are sure!" | |
return | |
fi | |
# assuming | |
GOROOT=$(pwd)/go/bin | |
# delete old deactivate file | |
rm -f deactivate | |
# set custom PATH | |
OLD_PATH=$PATH | |
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$GOROOT | |
# modify GOPATH | |
OLD_GOPATH=$GOPATH | |
export GOPATH=$(pwd) | |
mkdir -p $GOPATH/src $GOPATH/bin $GOPATH/pkg | |
echo "export PATH=$OLD_PATH | |
export GOPATH=$OLD_GOPATH | |
rm $(pwd)/deactivate" > deactivate | |
chmod +x deactivate | |
echo "run \". $(pwd)/deactivate\" to go back to original enviornment" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment