Skip to content

Instantly share code, notes, and snippets.

@tlehman
Last active April 22, 2022 02:47
Show Gist options
  • Save tlehman/c9d36df27f4f91386114acf03a1fd4f2 to your computer and use it in GitHub Desktop.
Save tlehman/c9d36df27f4f91386114acf03a1fd4f2 to your computer and use it in GitHub Desktop.
Go version manager in zsh using autocompletion
#!/usr/bin/zsh
# Go version manager by tlehman
# how to use: call _init_gvm in your .zshrc, then type "gvm -s <tab>" to have it autocomplete with all your installed go versions
function _gvm() {
local state
_arguments '-s[set go version]:go_version:->set_go'
case $state in
set_go)
for go_version in $(ls ~/sdk/); do
compadd $go_version
done
esac
}
function _init_gvm() {
# Bind your function to a command
compdef _gvm gvm # typing "gvm <tab>" will call gvm
}
if [ $# -eq 2 ]; then
echo "Setting Go version to $2"
fi
@tlehman
Copy link
Author

tlehman commented Apr 22, 2022

WIP, this is the first time I've gotten zsh autocompletion to work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment