mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-22 13:50:09 +00:00
sdk: improve sdkman completion (#8854)
This commit is contained in:
parent
c686aa3dbb
commit
373e27d805
1 changed files with 50 additions and 79 deletions
|
@ -1,81 +1,52 @@
|
||||||
|
#!/usr/bin/env zsh
|
||||||
|
|
||||||
### SDKMAN Autocomplete for Oh My Zsh
|
### SDKMAN Autocomplete for Oh My Zsh
|
||||||
|
|
||||||
# This is the output from sdkman. All the these options are supported at the
|
_sdk() {
|
||||||
# moment.
|
case "${CURRENT}" in
|
||||||
|
2)
|
||||||
# Usage: sdk <command> [candidate] [version]
|
compadd -X $'Commands:\n' -- "${${(Mk)functions[@]:#__sdk_*}[@]#__sdk_}"
|
||||||
# sdk offline <enable|disable>
|
compadd -n rm
|
||||||
#
|
;;
|
||||||
# commands:
|
3)
|
||||||
# install or i <candidate> [version] [local-path]
|
case "${words[2]}" in
|
||||||
# uninstall or rm <candidate> <version>
|
l|ls|list|i|install)
|
||||||
# list or ls [candidate]
|
compadd -X $'Candidates:\n' -- "${SDKMAN_CANDIDATES[@]}"
|
||||||
# use or u <candidate> <version>
|
;;
|
||||||
# default or d <candidate> [version]
|
ug|upgrade|c|current|u|use|d|default|rm|uninstall)
|
||||||
# current or c [candidate]
|
compadd -X $'Installed Candidates:\n' -- "${${(u)${(f)$(find -L -- "${SDKMAN_CANDIDATES_DIR}" -mindepth 2 -maxdepth 2 -type d)}[@]:h}[@]:t}"
|
||||||
# upgrade or ug [candidate]
|
;;
|
||||||
# version or v
|
offline)
|
||||||
# broadcast or b
|
compadd enable disable
|
||||||
# help or h
|
;;
|
||||||
# offline [enable|disable]
|
selfupdate)
|
||||||
# selfupdate [force]
|
compadd force
|
||||||
# update
|
;;
|
||||||
# flush <broadcast|archives|temp>
|
flush)
|
||||||
#
|
compadd archives broadcast temp version
|
||||||
# candidate : the SDK to install: groovy, scala, grails, gradle, kotlin, etc.
|
;;
|
||||||
# use list command for comprehensive list of candidates
|
|
||||||
# eg: $ sdk list
|
|
||||||
# version : where optional, defaults to latest stable if not provided
|
|
||||||
# eg: $ sdk install groovy
|
|
||||||
# local-path : optional path to an existing local installation
|
|
||||||
# eg: $ sdk install groovy 2.4.13-local /opt/groovy-2.4.13
|
|
||||||
|
|
||||||
local _sdk_commands=(
|
|
||||||
install i
|
|
||||||
uninstall rm
|
|
||||||
list ls
|
|
||||||
use u
|
|
||||||
default d
|
|
||||||
current c
|
|
||||||
upgrade ug
|
|
||||||
version v
|
|
||||||
broadcast b
|
|
||||||
help h
|
|
||||||
offline
|
|
||||||
selfupdate
|
|
||||||
update
|
|
||||||
flush
|
|
||||||
)
|
|
||||||
|
|
||||||
_listInstalledVersions() {
|
|
||||||
__sdkman_build_version_csv $1 | sed -e "s/,/ /g"
|
|
||||||
}
|
|
||||||
|
|
||||||
_listInstallableVersions() {
|
|
||||||
# Remove local (+) and installed (*) versions from the list
|
|
||||||
__sdkman_list_versions $1 | sed -e '/^[^ ]/d;s/[+*] [^ ]\+//g;s/>//g'
|
|
||||||
}
|
|
||||||
|
|
||||||
_listAllVersion() {
|
|
||||||
# Remove (*), (+), and (>) characters from the list
|
|
||||||
__sdkman_list_versions $1 | sed -e '/^[^ ]/d;s/[*+>] //g'
|
|
||||||
}
|
|
||||||
|
|
||||||
_sdk () {
|
|
||||||
case $CURRENT in
|
|
||||||
2) compadd -- $_sdk_commands ;;
|
|
||||||
3) case "$words[2]" in
|
|
||||||
i|install|rm|uninstall|ls|list|u|use|d|default|c|current|ug|upgrade)
|
|
||||||
compadd -- $SDKMAN_CANDIDATES ;;
|
|
||||||
offline) compadd -- enable disable ;;
|
|
||||||
selfupdate) compadd -- force ;;
|
|
||||||
flush) compadd -- broadcast archives temp ;;
|
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
4) case "$words[2]" in
|
4)
|
||||||
rm|uninstall|d|default) compadd -- $(_listInstalledVersions $words[3]) ;;
|
case "${words[2]}" in
|
||||||
i|install) compadd -- $(_listInstallableVersions $words[3]) ;;
|
i|install)
|
||||||
u|use) compadd -- $(_listAllVersion $words[3]) ;;
|
setopt localoptions kshglob
|
||||||
|
if [[ "${words[3]}" == 'java' ]]; then
|
||||||
|
compadd -X $'Installable Versions of java:\n' -- "${${${${${(f)$(__sdkman_list_versions "${words[3]}")}[@]:5:-4}[@]:#* | (local only|installed ) | *}[@]##* | | }[@]%%+( )}"
|
||||||
|
else
|
||||||
|
compadd -X "Installable Versions of ${words[3]}:"$'\n' -- "${${(z)${(M)${(f)${$(__sdkman_list_versions "${words[3]}")//[*+>]+( )/-}}[@]:# *}[@]}[@]:#-*}"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
u|use|d|default|rm|uninstall)
|
||||||
|
compadd -X "Installed Versions of ${words[3]}:"$'\n' -- "${${(f)$(find -L -- "${SDKMAN_CANDIDATES_DIR}/${words[3]}" -mindepth 1 -maxdepth 1 -type d -not -name 'current')}[@]:t}"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
5)
|
||||||
|
case "${words[2]}" in
|
||||||
|
i|install)
|
||||||
|
_files -X "Path to Local Installation of ${words[3]} ${words[4]}:"$'\n' -/
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
Loading…
Reference in a new issue