diff --git a/completions/asdf.bash b/completions/asdf.bash index b66c5e03..f828e9db 100644 --- a/completions/asdf.bash +++ b/completions/asdf.bash @@ -1,3 +1,12 @@ +_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 +) + _asdf() { local cur cur=${COMP_WORDS[COMP_CWORD]} @@ -71,13 +80,13 @@ _asdf() { # shellcheck disable=SC2207 COMPREPLY=($(compgen -W "--all" -- "$cur")) ;; - which) + which | shim-versions) # shellcheck disable=SC2207 - COMPREPLY=($(compgen -c -- "$cur")) + COMPREPLY=($(compgen -W "$(_asdf_list_shims)" -- "$cur")) ;; plugin-list | plugin-list-all | info) ;; *) - local cmds='current global help install latest list list-all local plugin-add plugin-list plugin-list-all plugin-remove plugin-update reshim shell uninstall update where which info' + 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' # shellcheck disable=SC2207 COMPREPLY=($(compgen -W "$cmds" -- "$cur")) ;; diff --git a/completions/asdf.fish b/completions/asdf.fish index d871d073..a309bf49 100644 --- a/completions/asdf.fish +++ b/completions/asdf.fish @@ -47,7 +47,7 @@ function __fish_asdf_plugin_list_all end function __fish_asdf_list_shims - ls $asdf_data_dir/shims + path basename $asdf_data_dir/shims/* end # update @@ -116,6 +116,10 @@ complete -f -c asdf -n __fish_asdf_needs_command -a reshim -d "Recreate shims fo complete -f -c asdf -n '__fish_asdf_using_command reshim; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)' complete -f -c asdf -n '__fish_asdf_using_command reshim; and __fish_asdf_arg_number 3' -a '(__fish_asdf_list_versions (__fish_asdf_arg_at 3))' +# shim-versions completion +complete -f -c asdf -n __fish_asdf_needs_command -a shim-versions -d "List the plugins and versions that provide a command" +complete -f -c asdf -n '__fish_asdf_using_command shim-versions; and __fish_asdf_arg_number 2' -a '(__fish_asdf_list_shims)' + # local completion complete -f -c asdf -n __fish_asdf_needs_command -a local -d "Set local version for a plugin" complete -f -c asdf -n '__fish_asdf_using_command local; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'