-
-
Save douglarek/e91668cd1675f67ff92ee13b9106946d to your computer and use it in GitHub Desktop.
A fish shell script for switching the version of Go.
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
function go_switch --argument-names 'verzion' # since version in fish shell is a bulit-in var | |
if not test -n "$verzion" | |
echo "Usage: go_switch [version]" | |
return 1 | |
end | |
if not type -q go # check bootstrap go | |
if [ (uname -i) != "x86_64" ] | |
echo "only x86_64 supported"; and return 1 | |
end | |
set os "linux" | |
switch (uname) | |
case Linux | |
case Darwin | |
set os "darwin" | |
case "*" | |
echo "only darwin and linux supported"; and return 1 | |
end | |
rm -rf ~/sdk/go$verzion; and mkdir -p ~/sdk/go$verzion; and \ | |
curl "https://storage.googleapis.com/golang/go$verzion.$os-amd64.tar.gz" -o ~/sdk/go$verzion.tar.gz; and \ | |
tar -xvf ~/sdk/go$verzion.tar.gz; and \ | |
mv ~/sdk/go ~/sdk/go$verzion; and rm -f ~/sdk/go$verzion.tar.gz; or return 1 | |
ln -sf ~/sdk/go$verzion/bin/go ~/bin/go; or return 1 | |
else | |
if not type -q go{$verzion} | |
echo "Go $verzion doesn't exist, start downloading..." | |
go get golang.org/dl/go{$verzion}; or return 1 | |
go{$verzion} download; or return 1 | |
end | |
go{$verzion} download &> /dev/null; or return 1 # maybe go binary not downloaded, so try it | |
set go_bin (command -v "go$verzion") | |
ln -sf $go_bin ~/bin/go; or return 1 | |
end | |
echo "Switched to Go $verzion" | |
set -gx fish_greeting '' | |
exec fish # reload fish | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment