mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-11-15 09:38:16 -07:00
zsh: handle 'foo bar' == 'foo-bar' and latest
asdf now optionally allows git-style 'foo bar' sub-commands, so the completion system should too. Implement support for `asdf latest` and `asdf install foo latest`
This commit is contained in:
parent
73c44e09ad
commit
f074257aa5
@ -6,14 +6,19 @@ local asdf_dir="${ASDF_DATA_DIR:-$HOME/.asdf}"
|
|||||||
|
|
||||||
local -a asdf_commands
|
local -a asdf_commands
|
||||||
asdf_commands=( # 'asdf help' lists commands with help text
|
asdf_commands=( # 'asdf help' lists commands with help text
|
||||||
|
# plugins
|
||||||
|
'plugin:plugin management sub-commands'
|
||||||
'plugin-add:add plugin from asdf-plugins repo or from git URL'
|
'plugin-add:add plugin from asdf-plugins repo or from git URL'
|
||||||
'plugin-list:list installed plugins (--url with URLs)'
|
'plugin-list:list installed plugins (--url with URLs)'
|
||||||
'plugin-list-all:list all plugins registered in asdf-plugins repo'
|
'plugin-list-all:list all plugins registered in asdf-plugins repo'
|
||||||
'plugin-remove:remove named plugin and all packages for it'
|
'plugin-remove:remove named plugin and all packages for it'
|
||||||
'plugin-update:update named plugin (or --all)'
|
'plugin-update:update named plugin (or --all)'
|
||||||
|
|
||||||
|
# packages
|
||||||
'install:install plugin at stated version, or all from .tools-versions'
|
'install:install plugin at stated version, or all from .tools-versions'
|
||||||
'uninstall:remove a specific version of a package'
|
'uninstall:remove a specific version of a package'
|
||||||
'current:display current versions for named package (else all)'
|
'current:display current versions for named package (else all)'
|
||||||
|
'latest:display latest version available to install for a named package'
|
||||||
'where:display install path for given package at optional specified version'
|
'where:display install path for given package at optional specified version'
|
||||||
'which:display path to an executable'
|
'which:display path to an executable'
|
||||||
'shell:via env vars, set package to version in current shell'
|
'shell:via env vars, set package to version in current shell'
|
||||||
@ -21,9 +26,12 @@ asdf_commands=( # 'asdf help' lists commands with help text
|
|||||||
'global:set package global version'
|
'global:set package global version'
|
||||||
'list:list installed versions of a package'
|
'list:list installed versions of a package'
|
||||||
'list-all:list all available (remote) versions of a package'
|
'list-all:list all available (remote) versions of a package'
|
||||||
|
|
||||||
|
# utils
|
||||||
'exec:executes the command shim for the current version'
|
'exec:executes the command shim for the current version'
|
||||||
'env:prints or runs an executable under a command environment'
|
'env:prints or runs an executable under a command environment'
|
||||||
'reshim:recreate shims for version of a package'
|
'reshim:recreate shims for version of a package'
|
||||||
|
'shim:shim management sub-commands'
|
||||||
'shim-versions:list for given command which plugins and versions provide it'
|
'shim-versions:list for given command which plugins and versions provide it'
|
||||||
'update:update ASDF to the latest stable release (unless --head)'
|
'update:update ASDF to the latest stable release (unless --head)'
|
||||||
)
|
)
|
||||||
@ -67,6 +75,8 @@ _asdf__installed_versions_of() {
|
|||||||
compadd -a versions
|
compadd -a versions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local -i IntermediateCount=0
|
||||||
|
|
||||||
if (( CURRENT == 2 )); then
|
if (( CURRENT == 2 )); then
|
||||||
_arguments -C : '--version[version]' ':command:->command'
|
_arguments -C : '--version[version]' ':command:->command'
|
||||||
fi
|
fi
|
||||||
@ -80,33 +90,78 @@ esac
|
|||||||
subcmd="${words[2]}"
|
subcmd="${words[2]}"
|
||||||
curcontext="${curcontext%:*}=$subcmd:"
|
curcontext="${curcontext%:*}=$subcmd:"
|
||||||
|
|
||||||
|
# Handle 'foo bar' == 'foo-bar'
|
||||||
|
_asdf__dash_commands() {
|
||||||
|
if (( CURRENT == 3 + IntermediateCount )); then
|
||||||
|
local -a sub_commands
|
||||||
|
sub_commands=(${${(M)asdf_commands:#${subcmd}-*}#${subcmd}-})
|
||||||
|
_describe -t asdf-commands 'ASDF Commands' sub_commands
|
||||||
|
else
|
||||||
|
IntermediateCount+=1
|
||||||
|
subcmd="${subcmd}-${words[2+IntermediateCount]}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
case "$subcmd" in
|
||||||
|
(plugin|shim|list)
|
||||||
|
_asdf__dash_commands
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
case "$subcmd" in
|
||||||
|
(plugin-list)
|
||||||
|
_asdf__dash_commands
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
case "$subcmd" in
|
case "$subcmd" in
|
||||||
(plugin-add)
|
(plugin-add)
|
||||||
if (( CURRENT == 3 )); then
|
if (( CURRENT == 3 + IntermediateCount )); then
|
||||||
_asdf__available_plugins
|
_asdf__available_plugins
|
||||||
else
|
else
|
||||||
# Optional URL
|
# Optional URL
|
||||||
curcontext="${curcontext/=plugin-add:/=plugin-add-${words[3]}:}"
|
curcontext="${curcontext/=plugin-add:/=plugin-add-${words[3]}:}"
|
||||||
if (( CURRENT == 4 )); then
|
if (( CURRENT == 4 + IntermediateCount )); then
|
||||||
_arguments "*:${words[3]} package url:_urls"
|
_arguments "*:${words[3]} package url:_urls"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
(plugin-remove|current|list|list-all)
|
(plugin-remove|current|list|list-all)
|
||||||
(( CURRENT == 3 )) && _asdf__installed_plugins
|
(( CURRENT == 3 + IntermediateCount )) && _asdf__installed_plugins
|
||||||
;;
|
;;
|
||||||
(plugin-update)
|
(plugin-update)
|
||||||
(( CURRENT == 3 )) && _alternative \
|
(( CURRENT == 3 + IntermediateCount )) && _alternative \
|
||||||
'all:all:(--all)' \
|
'all:all:(--all)' \
|
||||||
'asdf-available-plugins:Installed ASDF Plugins:_asdf__installed_plugins'
|
'asdf-available-plugins:Installed ASDF Plugins:_asdf__installed_plugins'
|
||||||
;;
|
;;
|
||||||
(install)
|
(install)
|
||||||
if (( CURRENT == 3 )); then
|
if (( CURRENT == 3 + IntermediateCount )); then
|
||||||
_asdf__installed_plugins
|
_asdf__installed_plugins
|
||||||
elif (( CURRENT == 4 )); then
|
elif (( CURRENT == 4 + IntermediateCount )); then
|
||||||
_wanted "remote-versions-${words[3]}" \
|
local pkg="${words[3+IntermediateCount]}"
|
||||||
expl "Available versions of ${words[3]}" \
|
local ver_prefix="${words[4+IntermediateCount]}"
|
||||||
compadd -- $(asdf list-all "${words[3]}")
|
if [[ $ver_prefix == latest:* ]]; then
|
||||||
|
_wanted "latest-versions-$pkg" \
|
||||||
|
expl "Latest version" \
|
||||||
|
compadd -- latest:${^$(asdf list-all "$pkg")}
|
||||||
|
else
|
||||||
|
_wanted "latest-tag-$pkg" \
|
||||||
|
expl "Latest version" \
|
||||||
|
compadd -- 'latest' 'latest:'
|
||||||
|
_wanted "remote-versions-$pkg" \
|
||||||
|
expl "Available versions of $pkg" \
|
||||||
|
compadd -- $(asdf list-all "$pkg")
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
(latest)
|
||||||
|
if (( CURRENT == 3 + IntermediateCount )); then
|
||||||
|
_asdf__installed_plugins
|
||||||
|
elif (( CURRENT == 4 + IntermediateCount )); then
|
||||||
|
local pkg="${words[3+IntermediateCount]}"
|
||||||
|
local query=${words[4+IntermediateCount]}
|
||||||
|
[[ -n $query ]] || query='[0-9]'
|
||||||
|
_wanted "latest-pattern-$pkg" \
|
||||||
|
expl "Pattern to look for in matching versions of $pkg" \
|
||||||
|
compadd -- $(asdf list-all "$pkg" "$query")
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
(uninstall|shell|local|global|reshim)
|
(uninstall|shell|local|global|reshim)
|
||||||
|
Loading…
Reference in New Issue
Block a user