fix: support asdf shim-versions completions in fish & bash (#1554)

authored-by: Yuri Pieters <yuri.pieters@anaplan.com>
This commit is contained in:
Yuri Pieters 2023-05-31 09:29:50 +01:00 committed by GitHub
parent d8ce35357f
commit 99623d7eac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 4 deletions

View File

@ -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() { _asdf() {
local cur local cur
cur=${COMP_WORDS[COMP_CWORD]} cur=${COMP_WORDS[COMP_CWORD]}
@ -71,13 +80,13 @@ _asdf() {
# shellcheck disable=SC2207 # shellcheck disable=SC2207
COMPREPLY=($(compgen -W "--all" -- "$cur")) COMPREPLY=($(compgen -W "--all" -- "$cur"))
;; ;;
which) which | shim-versions)
# shellcheck disable=SC2207 # shellcheck disable=SC2207
COMPREPLY=($(compgen -c -- "$cur")) COMPREPLY=($(compgen -W "$(_asdf_list_shims)" -- "$cur"))
;; ;;
plugin-list | plugin-list-all | info) ;; 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 # shellcheck disable=SC2207
COMPREPLY=($(compgen -W "$cmds" -- "$cur")) COMPREPLY=($(compgen -W "$cmds" -- "$cur"))
;; ;;

View File

@ -47,7 +47,7 @@ function __fish_asdf_plugin_list_all
end end
function __fish_asdf_list_shims function __fish_asdf_list_shims
ls $asdf_data_dir/shims path basename $asdf_data_dir/shims/*
end end
# update # 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 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))' 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 # 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_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)' complete -f -c asdf -n '__fish_asdf_using_command local; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'