Created
December 28, 2021 12:15
-
-
Save lacunoc/d643d93c15800a015e54b950d5b4ef9a to your computer and use it in GitHub Desktop.
Switch golang version on demand
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
alias gsv="source /usr/local/bin/go_switch_version.sh" |
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 zsh | |
| |
if [ $# -eq 0 ]; then | |
echo "No go version provided" | |
exit 1 | |
fi | |
| |
VERSION=$1 | |
ALIAS_FOUND=`grep -c "alias go" ~/.zprofile` | |
| |
if [ "$VERSION" != "latest" ] | |
then | |
sudo go install golang.org/dl/go${VERSION}@latest | |
go${VERSION} download | |
else | |
VERSION="" | |
fi | |
| |
sed -i '' '/^alias go.*$/d' ~/.zprofile | |
echo "alias go=/usr/local/go/bin/go${VERSION}" >> ~/.zprofile | |
| |
source ~/.zprofile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment