sdk.plugin.zsh 1.54 KB
Newer Older
1
#!/usr/bin/env zsh
2

3
### SDKMAN Autocomplete for Oh My Zsh
4

5
6
7
8
9
10
11
12
13
14
15
_sdk() {
	case "${CURRENT}" in
	2)
		compadd -X $'Commands:\n' -- "${${(Mk)functions[@]:#__sdk_*}[@]#__sdk_}"
		compadd -n rm
		;;
	3)
		case "${words[2]}" in
		l|ls|list|i|install)
			compadd -X $'Candidates:\n' -- "${SDKMAN_CANDIDATES[@]}"
			;;
16
		ug|upgrade|h|home|c|current|u|use|d|default|rm|uninstall)
17
18
			compadd -X $'Installed Candidates:\n' -- "${${(u)${(f)$(find -L -- "${SDKMAN_CANDIDATES_DIR}" -mindepth 2 -maxdepth 2 -type d)}[@]:h}[@]:t}"
			;;
19
20
21
		e|env)
			compadd init
			;;
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
		offline)
			compadd enable disable
			;;
		selfupdate)
			compadd force
			;;
		flush)
			compadd archives broadcast temp version
			;;
		esac
		;;
	4)
		case "${words[2]}" in
		i|install)
			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
			;;
43
		h|home|u|use|d|default|rm|uninstall)
44
45
46
47
48
49
50
51
52
53
54
55
			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
56
57
58
}

compdef _sdk sdk