-
Notifications
You must be signed in to change notification settings - Fork 2
/
_kss
57 lines (49 loc) · 1.42 KB
/
_kss
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
#compdef kss
local ret=1 state
local -a namespace pods
local kubectl=kubectl
(( $+functions[_kss_cache_policy] )) ||
_kss_cache_policy () {
typeset -a old
# cache is valid for 1mn
old=( "$1"(mm+1) )
(( $#old ))
}
local args=(
{-h,--help}'[display help message]' \
{-l,--showlog}'[Show log]' \
{-A,--annotations}'[Show annotations]' \
{-L,--labels}'[Show labels]' \
{-r,--restrict}'[Retrict pods to]: :' \
{-n,--namespace}'[Use namespace]:Use namespace:->namespace' \
'*:pods:->pods'
)
_arguments -S -C $args && ret=0
case $state in
namespace)
zstyle ":completion:${curcontext}:" cache-policy _kss_cache_policy
local cacheid=kubectl_namespaces
typeset -a namespaces
local namespaceflg
if _cache_invalid "$cacheid" || ! _retrieve_cache "$cacheid"
then
namespaces=(${(@f)$(command ${kubectl} get namespace -o name)#namespace/##})
_store_cache "$cacheid" namespaces
fi
_describe 'all namespace' namespaces && ret=0
;;
pods)
for (( i = 1; i <= $#words - 1; i++ )); do
if [[ $words[$i] == -n || $words[$i] == --namespace ]]; then
kubectl="kubectl --namespace $words[$((i+1))]"
break
fi
done
pods=(${(@f)$(_call_program pod ${kubectl} get pod -o name)#pod/##})
_describe 'all pods' pods && ret=0
;;
esac
return ret
# Local Variables:
# mode: shell-script
# End: