Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions completions/asdf.bash
Original file line number Diff line number Diff line change
@@ -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]}
Expand Down Expand Up @@ -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"))
;;
Expand Down
6 changes: 5 additions & 1 deletion completions/asdf.fish
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)'
Expand Down