Skip to content

Instantly share code, notes, and snippets.

@mikalv
Forked from AnomalRoil/go-switch-bash
Created July 1, 2022 11:11
Show Gist options
  • Save mikalv/0152ae3ca40fdd2768d52a89675049bb to your computer and use it in GitHub Desktop.
Save mikalv/0152ae3ca40fdd2768d52a89675049bb 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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment