asdf/completions/asdf.bash

69 lines
2.1 KiB
Bash
Raw Normal View History

2019-11-29 09:15:38 -07:00
_asdf() {
local cur
cur=${COMP_WORDS[COMP_CWORD]}
local cmd
cmd=${COMP_WORDS[1]}
local prev
2019-11-29 09:15:38 -07:00
prev=${COMP_WORDS[COMP_CWORD - 1]}
local plugins
2019-11-29 09:15:38 -07:00
plugins=$(asdf plugin-list 2>/dev/null | tr '\n' ' ')
2016-02-29 00:53:43 -07:00
# We can safely ignore warning SC2207 since it warns that it will uses the
# shell's sloppy word splitting and globbing. The possible commands here are
# all single words, and most likely won't contain special chars the shell will
# expand.
2016-02-29 00:53:43 -07:00
COMPREPLY=()
case "$cmd" in
plugin-update)
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "$plugins --all" -- "$cur"))
2016-02-29 00:53:43 -07:00
;;
2019-11-29 09:15:38 -07:00
plugin-remove | current | list | list-all)
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "$plugins" -- "$cur"))
2016-02-29 00:53:43 -07:00
;;
plugin-add)
local available_plugins
2020-01-28 02:23:42 -07:00
available_plugins=$(asdf plugin-list-all 2>/dev/null | awk '{ if ($2 !~ /^\*/) print $1}')
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "$available_plugins" -- "$cur"))
;;
2016-02-29 00:53:43 -07:00
install)
2019-11-29 09:15:38 -07:00
if [[ "$plugins" == *"$prev"* ]]; then
local versions
2019-11-29 09:15:38 -07:00
versions=$(asdf list-all "$prev" 2>/dev/null)
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "$versions" -- "$cur"))
2016-02-29 00:53:43 -07:00
else
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "$plugins" -- "$cur"))
2016-02-29 00:53:43 -07:00
fi
;;
update)
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "--head" -- "$cur"))
;;
2019-11-29 09:15:38 -07:00
uninstall | where | reshim | local | global | shell)
if [[ "$plugins" == *"$prev"* ]]; then
local versions
2019-11-29 09:15:38 -07:00
versions=$(asdf list "$prev" 2>/dev/null)
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "$versions" -- "$cur"))
2016-02-29 00:53:43 -07:00
else
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "$plugins" -- "$cur"))
2016-02-29 00:53:43 -07:00
fi
;;
*)
local cmds='current global help install list list-all local plugin-add plugin-list plugin-list-all plugin-remove plugin-update reshim shell uninstall update where which '
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "$cmds" -- "$cur"))
2016-02-29 00:53:43 -07:00
;;
esac
return 0
}
complete -F _asdf asdf