-
Notifications
You must be signed in to change notification settings - Fork 1
/
bash_autocomplete
39 lines (36 loc) · 1.08 KB
/
bash_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
#!/usr/bin/env bash
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
}
: ${PROG:=$(basename ${BASH_SOURCE})}
_cli_bash_autocomplete() {
if [[ "${COMP_WORDS[0]}" != "source" ]]; then
local cur opts base
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
if [[ "$cur" == "-"* ]]; then
opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} ${cur} --generate-bash-completion )
elif [[ ${COMP_WORDS[-2]} == "--sc" || ${COMP_WORDS[-2]} == "--storageclass" ]];then
opts=$(getscs)
elif [[ ${COMP_WORDS[-2]} == "--vsc" || ${COMP_WORDS[-2]} == "--volumeSnapshotClass" ]];then
opts=$(getvscs)
else
opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-bash-completion )
fi
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
fi
}
complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete $PROG
unset PROG