sdk.plugin.zsh 2.54 KB
Newer Older
1
2
3
4
5
6
7
8
9
### SDKMAN Autocomplete for Oh My Zsh

# This is the output from sdkman. All the these options are supported at the
# moment.

# Usage: sdk <command> [candidate] [version]
#        sdk offline <enable|disable>
#
#    commands:
10
#        install   or i    <candidate> [version] [local-path]
11
12
#        uninstall or rm   <candidate> <version>
#        list      or ls   [candidate]
13
#        use       or u    <candidate> <version>
14
15
16
17
18
19
20
21
22
#        default   or d    <candidate> [version]
#        current   or c    [candidate]
#        upgrade   or ug   [candidate]
#        version   or v
#        broadcast or b
#        help      or h
#        offline           [enable|disable]
#        selfupdate        [force]
#        update
23
#        flush             <broadcast|archives|temp>
24
25
26
27
28
29
#
#    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
30
31
#    local-path :  optional path to an existing local installation
#                  eg: $ sdk install groovy 2.4.13-local /opt/groovy-2.4.13
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

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() {
55
56
  # Remove local (+) and installed (*) versions from the list
  __sdkman_list_versions $1 | sed -e '/^[^ ]/d;s/[+*] [^ ]\+//g;s/>//g'
57
58
59
}

_listAllVersion() {
60
61
  # Remove (*), (+), and (>) characters from the list
  __sdkman_list_versions $1 | sed -e '/^[^ ]/d;s/[*+>] //g'
62
63
64
65
66
67
68
69
70
71
}

_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 ;;
72
          flush)      compadd -- broadcast archives temp ;;
73
74
75
76
77
78
79
80
81
82
83
84
        esac
        ;;
    4)  case "$words[2]" in
          rm|uninstall|d|default) compadd -- $(_listInstalledVersions $words[3]) ;;
          i|install)              compadd -- $(_listInstallableVersions $words[3]) ;;
          u|use)                  compadd -- $(_listAllVersion $words[3]) ;;
        esac
        ;;
  esac
}

compdef _sdk sdk