forked from dell/cert-csi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zsh_autocomplete
57 lines (50 loc) · 1.29 KB
/
zsh_autocomplete
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env zsh
#compdef $PROG
getscs(){
TEST=$(kubectl get sc 2>&1)
if [ $? -eq 0 ];then
rez=$(echo "$TEST" | tail -n +2 | cut -d" " -f1)
echo "$rez"
fi
}
getvscs(){
TEST=$(kubectl get volumesnapshotclass 2>&1)
if [ $? -eq 0 ];then
rez=$(echo "$TEST" | tail -n +2 | cut -d" " -f1)
echo "$rez"
fi
}
_cli_zsh_autocomplete() {
local -a subcmds
local -a opts
local cur
cur=${words[-1]}
if [[ "$cur" == "-"* ]]; then
opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} ${cur} --generate-bash-completion)}")
else
opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} --generate-bash-completion)}")
fi
if [[ "${opts[1]}" != "" ]]; then
_describe 'values' opts
else
if [[ ${words[-2]} == "--sc" || ${words[-2]} == "--storageclass" ]];then
res=$(getscs)
while read -r line; do array+=("$line"); done <<<"$res"
for element in "${array[@]}"
do
compadd $element
done
elif [[ ${words[-2]} == "--vsc" || ${words[-2]} == "--volumeSnapshotClass" ]];then
ressnap=$(getvscs)
while read -r line; do arraysnap+=("$line"); done <<<"$ressnap"
for element in "${arraysnap[@]}"
do
compadd $element
done
else
_files
fi
fi
return
}
compdef _cli_zsh_autocomplete $PROG