diff --git a/bash/bashrc.bash b/bash/bashrc.bash index 5a09bb8..08272f9 100644 --- a/bash/bashrc.bash +++ b/bash/bashrc.bash @@ -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" diff --git a/bash/functions.bash b/bash/functions.bash index e306f1e..f1ca5f3 100644 --- a/bash/functions.bash +++ b/bash/functions.bash @@ -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)) } diff --git a/bash/gover.bash b/bash/gover.bash new file mode 100644 index 0000000..5303719 --- /dev/null +++ b/bash/gover.bash @@ -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