From 29d0f8a746291525178ab63dd5a037b3d5ba11dc Mon Sep 17 00:00:00 2001 From: Yuri Pieters Date: Wed, 3 May 2023 10:24:36 +0100 Subject: [PATCH 1/4] feat: add shim-versions completion for fish --- completions/asdf.fish | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/completions/asdf.fish b/completions/asdf.fish index d871d073a..b7f4a985f 100644 --- a/completions/asdf.fish +++ b/completions/asdf.fish @@ -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)' From 8412ca618e05222ec7c9d6814e5918e30ea51d62 Mon Sep 17 00:00:00 2001 From: Yuri Pieters Date: Wed, 3 May 2023 10:34:21 +0100 Subject: [PATCH 2/4] fix: use basename & a glob to list shims in fish `ls` is meant for users, so the output isn't meant to be suitable for scripts. Users may have aliases that change the output of the command, such as adding icons. --- completions/asdf.fish | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/completions/asdf.fish b/completions/asdf.fish index b7f4a985f..a309bf49d 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 From ba6f1b8664d3a577020014083f601c5cceaf1b89 Mon Sep 17 00:00:00 2001 From: Yuri Pieters Date: Wed, 3 May 2023 10:35:27 +0100 Subject: [PATCH 3/4] feat: add shim-versions completion for bash --- completions/asdf.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/completions/asdf.bash b/completions/asdf.bash index b66c5e030..44e5e1849 100644 --- a/completions/asdf.bash +++ b/completions/asdf.bash @@ -71,13 +71,13 @@ _asdf() { # shellcheck disable=SC2207 COMPREPLY=($(compgen -W "--all" -- "$cur")) ;; - which) + which | shim-versions) # shellcheck disable=SC2207 COMPREPLY=($(compgen -c -- "$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")) ;; From cdc158092b0f89021b32df230d48dab95ca375fc Mon Sep 17 00:00:00 2001 From: Yuri Pieters Date: Wed, 3 May 2023 11:06:48 +0100 Subject: [PATCH 4/4] fix: complete only asdf shims in bash Rather than completing all available commands, only complete the shims provided by asdf. This aligns with the completion in other shells. --- completions/asdf.bash | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/completions/asdf.bash b/completions/asdf.bash index 44e5e1849..f828e9db5 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]} @@ -73,7 +82,7 @@ _asdf() { ;; which | shim-versions) # shellcheck disable=SC2207 - COMPREPLY=($(compgen -c -- "$cur")) + COMPREPLY=($(compgen -W "$(_asdf_list_shims)" -- "$cur")) ;; plugin-list | plugin-list-all | info) ;; *)