Skip to content

Instantly share code, notes, and snippets.

@AnomalRoil
Last active July 1, 2022 13:37
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save AnomalRoil/48d557f86c25844320a6b13bf16fd50f to your computer and use it in GitHub Desktop.
Save AnomalRoil/48d557f86c25844320a6b13bf16fd50f to your computer and use it in GitHub Desktop.
The `go switch` function allows you to easily switch you current Go version
# to add to your ~/.bashrc or your ~/.zshrc file. Usage: $ go switch 1.18.1
function go() {
case $* in
switch* )
shift 1
gobindir=$(go env GOBIN)
# adapt to a valid directory at the beginning of your $PATH if you're not on systemd
homebindir=$(systemd-path user-binaries)
go install golang.org/dl/go"$@"@latest
$gobindir/go"$@" download
ln -sf $gobindir/go"$@" $homebindir/go
echo "$@ was symlinked to $homebindir/go ; You can run 'go version' to check."
;;
* )
command go "$@"
;;
esac
}
@AnomalRoil
Copy link
Author

Demo:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment