fix: consistent system completion (#911)

This commit is contained in:
Honeypot95 2021-04-18 05:04:18 +02:00 committed by GitHub
parent 1b8847b865
commit f4a80b53df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 2 deletions

View File

@ -76,6 +76,21 @@ _asdf__installed_versions_of() {
compadd -a versions
}
_asdf__installed_versions_of_plus_system() {
local plugin_dir="${asdf_dir:?}/installs/${1:?need a plugin version}"
if [[ ! -d "$plugin_dir" ]]; then
_wanted "asdf-versions-$1" expl "ASDF Plugin ${(q-)1} versions" \
compadd -x "no versions installed"
return
fi
local -a versions
versions=( "$plugin_dir"/*(:t) )
versions+="system"
_wanted "asdf-versions-$1" expl "ASDF Plugin ${(q-)1} versions" \
compadd -a versions
}
local -i IntermediateCount=0
if (( CURRENT == 2 )); then
@ -165,10 +180,14 @@ case "$subcmd" in
compadd -- $(asdf list-all "$pkg" "$query")
fi
;;
(uninstall|shell|local|global|reshim)
(uninstall|reshim)
compset -n 2
_arguments '1:plugin-name: _asdf__installed_plugins' '2:package-version:{_asdf__installed_versions_of ${words[2]}}'
;;
(shell|local|global)
compset -n 2
_arguments '1:plugin-name: _asdf__installed_plugins' '2:package-version:{_asdf__installed_versions_of_plus_system ${words[2]}}'
;;
(where)
# version is optional
compset -n 2

View File

@ -44,7 +44,7 @@ _asdf() {
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "--head" -- "$cur"))
;;
uninstall | where | reshim | local | global | shell)
uninstall | where | reshim)
if [[ "$plugins" == *"$prev"* ]]; then
local versions
versions=$(asdf list "$prev" 2>/dev/null)
@ -55,6 +55,18 @@ _asdf() {
COMPREPLY=($(compgen -W "$plugins" -- "$cur"))
fi
;;
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
;;
*)
local cmds='current global help install list list-all local plugin-add plugin-list plugin-list-all plugin-remove plugin-update reshim shell uninstall update where which info'
# shellcheck disable=SC2207