1
0
Fork 0

Go version manager

This commit is contained in:
Gregory Eremin 2019-10-10 00:55:27 +02:00
parent e6f30324a5
commit 2f17a9f730
3 changed files with 42 additions and 5 deletions

View File

@ -24,6 +24,7 @@ __bash_import "iterm"
__bash_import "alias"
__bash_import "prompt"
__bash_import "functions"
__bash_import "gover"
__bash_import "docker"
__bash_import "secrets"

View File

@ -24,9 +24,7 @@ function shuf {
}
function __bash_ssh_complete {
local cur=${COMP_WORDS[COMP_CWORD]}
local opts=$(cat $HOME/.ssh/known_hosts | cut -d' ' -f1 | cut -d, -f1)
COMPREPLY=($(compgen -o nospace -W "$opts" -- $cur))
__bash_complete "$(cat $HOME/.ssh/known_hosts | cut -d' ' -f1 | cut -d, -f1)"
}
complete -F __bash_ssh_complete ssh
@ -46,7 +44,15 @@ function cg { cd $GOPATH/src/github.com/$1; }
function _cg { __bash_directory_complete $GOPATH/src/github.com; }
complete -F _cg cg
#
# Misc
#
function __bash_directory_complete {
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=($(compgen -o nospace -W "$(ls $1)" -- $cur))
__bash_complete "$(ls $1)"
}
function __bash_complete {
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=($(compgen -o nospace -W "$1" -- $cur))
}

30
bash/gover.bash Normal file
View File

@ -0,0 +1,30 @@
# Go version manager
# Step 1: Download & Extract
# Step 2: mv ~/Downloads/go ~/go/versions/x.y.z
# GOROOT=$HOME/go/lang
# GOPATH=$HOME/go/path
function gover { ln -sfn $HOME/go/versions/$1 $HOME/go/lang; }
function _gover { __bash_directory_complete $HOME/go/versions; }
complete -F _gover gover
function godl {
wget https://dl.google.com/go/go$1.darwin-amd64.tar.gz -O /tmp/go$1.darwin-amd64.tar.gz
mkdir /tmp/go$1
tar -xzf /tmp/go$1.darwin-amd64.tar.gz -C /tmp/go$1
mv /tmp/go$1/go $HOME/go/versions/$1
rmdir /tmp/go$1
}
function __gover_download_list {
curl -s https://golang.org/dl/ \
| grep "https://dl.google.com" \
| cut -d '"' -f6 \
| cut -d/ -f5 \
| cut -d. -f1-3 \
| cut -c3- \
| grep -e '[0-9]\.[0-9]*\.[0-9]' \
| sort -Vur
}
function _godl {
__bash_complete "$(__gover_download_list $1)"
}
complete -F _godl godl