2023-05-31 01:29:50 -07:00
_asdf_list_shims( ) (
# this function runs in a subshell so shopt is scoped
shopt -s nullglob # globs that don't match should disappear
shopt -u failglob # globs that don't match shouldn't fail
for shim in " ${ ASDF_DATA_DIR :- $HOME /.asdf } " /shims/*; do
basename " $shim "
done
)
2016-02-29 00:53:43 -07:00
_asdf( ) {
2017-08-31 20:21:09 -07:00
local cur
cur = ${ COMP_WORDS [COMP_CWORD] }
local cmd
cmd = ${ COMP_WORDS [1] }
local prev
prev = ${ COMP_WORDS [COMP_CWORD - 1] }
local plugins
2018-11-16 05:25:33 -07:00
plugins = $( asdf plugin-list 2>/dev/null | tr '\n' ' ' )
2016-02-29 00:53:43 -07:00
2017-12-27 08:45:16 -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
2020-06-29 16:16:35 -07:00
plugin-update)
# shellcheck disable=SC2207
COMPREPLY = ( $( compgen -W " $plugins --all " -- " $cur " ) )
; ;
2022-10-18 06:54:03 -07:00
plugin-remove | current)
2020-06-29 16:16:35 -07:00
# shellcheck disable=SC2207
COMPREPLY = ( $( compgen -W " $plugins " -- " $cur " ) )
; ;
plugin-add)
local available_plugins
available_plugins = $( asdf plugin-list-all 2>/dev/null | awk '{ if ($2 !~ /^\*/) print $1}' )
# shellcheck disable=SC2207
COMPREPLY = ( $( compgen -W " $available_plugins " -- " $cur " ) )
; ;
2022-10-18 06:54:03 -07:00
install | list | list-all | help )
2020-06-29 16:16:35 -07:00
if [ [ " $plugins " = = *" $prev " * ] ] ; then
local versions
versions = $( asdf list-all " $prev " 2>/dev/null)
2017-12-27 08:45:16 -07:00
# shellcheck disable=SC2207
2020-06-29 16:16:35 -07:00
COMPREPLY = ( $( compgen -W " $versions " -- " $cur " ) )
else
2017-12-27 08:45:16 -07:00
# shellcheck disable=SC2207
2017-08-31 20:21:09 -07:00
COMPREPLY = ( $( compgen -W " $plugins " -- " $cur " ) )
2020-06-29 16:16:35 -07:00
fi
; ;
update)
# shellcheck disable=SC2207
COMPREPLY = ( $( compgen -W "--head" -- " $cur " ) )
; ;
2021-04-17 20:04:18 -07:00
uninstall | where | reshim)
2020-06-29 16:16:35 -07:00
if [ [ " $plugins " = = *" $prev " * ] ] ; then
local versions
versions = $( asdf list " $prev " 2>/dev/null)
2018-01-22 21:46:47 -07:00
# shellcheck disable=SC2207
2020-06-29 16:16:35 -07:00
COMPREPLY = ( $( compgen -W " $versions " -- " $cur " ) )
else
2018-01-22 21:46:47 -07:00
# shellcheck disable=SC2207
2020-06-29 16:16:35 -07:00
COMPREPLY = ( $( compgen -W " $plugins " -- " $cur " ) )
fi
; ;
2021-04-17 20:04:18 -07:00
local | global | shell)
if [ [ " $plugins " = = *" $prev " * ] ] ; then
local versions
versions = $( asdf list " $prev " 2>/dev/null)
versions += " system"
# shellcheck disable=SC2207
COMPREPLY = ( $( compgen -W " $versions " -- " $cur " ) )
else
# shellcheck disable=SC2207
COMPREPLY = ( $( compgen -W " $plugins " -- " $cur " ) )
fi
; ;
2022-08-22 06:54:10 -07:00
latest)
# shellcheck disable=SC2207
COMPREPLY = ( $( compgen -W "--all" -- " $cur " ) )
; ;
2023-05-31 01:29:50 -07:00
which | shim-versions)
2022-10-18 06:54:03 -07:00
# shellcheck disable=SC2207
2023-05-31 01:29:50 -07:00
COMPREPLY = ( $( compgen -W " $( _asdf_list_shims) " -- " $cur " ) )
2022-10-18 06:54:03 -07:00
; ;
plugin-list | plugin-list-all | info) ; ;
2020-06-29 16:16:35 -07:00
*)
2023-05-31 01:29:50 -07:00
local cmds = 'current global help install latest list list-all local plugin-add plugin-list plugin-list-all plugin-remove plugin-update reshim shim-versions shell uninstall update where which info'
2020-06-29 16:16:35 -07:00
# shellcheck disable=SC2207
COMPREPLY = ( $( compgen -W " $cmds " -- " $cur " ) )
; ;
2016-02-29 00:53:43 -07:00
esac
return 0
}
complete -F _asdf asdf