Skip to content

Instantly share code, notes, and snippets.

@tsujp
Forked from AnomalRoil/go-switch-bash
Created June 30, 2022 06:45
Show Gist options
  • Save tsujp/1d550fc8b89b9c0a1fad19032c79bbfe to your computer and use it in GitHub Desktop.
Save tsujp/1d550fc8b89b9c0a1fad19032c79bbfe 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