-
Notifications
You must be signed in to change notification settings - Fork 0
/
kgg
executable file
·72 lines (66 loc) · 1.47 KB
/
kgg
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
set -eu
set -o pipefail
help() {
cat <<EOT
Gets the full name of pods filtered by a pattern or interactively picked. If
multiple results are found then interactive use is forced.
OPTIONS
-h|--help
This help
[-g|--grep] pattern ...
Only include results matching <pattern>.
If multiple patterns are given, all must match.
-i|--ignore pattern ...
Exclude results matching <pattern>.
-n|--namespace namespace
Limit to the given namespace, otherwise checks all.
-p|--percol ...
Interactively filter the resources with Percol.
-k|--kind kind ...
Search for something other than pods.
EOT
}
PASS=()
KIND="pods"
NS=""
while (( ${#*} > 0 )); do
case $1 in
-h|--help)
help
exit;;
-k|--kind)
shift; KIND="$1"
shift;;
-n|--namespace)
shift; NS="$1"
shift;;
*)
PASS+=("$1")
shift;;
esac
done
if [ -z "$NS" ]; then
NS_FLAG="-A"
else
NS_FLAG="-n $NS"
fi
PICKED=$(kubectl get $NS_FLAG $KIND | pick --skip-header-line "${PASS[@]}")
while true; do
# echo "PICKED $PICKED"
NUM_PICKED=$(wc -l <<<"$PICKED")
case "$NUM_PICKED" in
0)
echo "0 results" >&2
exit;;
1)
if [ -z "$NS" ]; then
awk '{print "-n " $1 " " $2}' <<<"$PICKED"
else
awk '{print "'"$NS_FLAG"' " $1}' <<<"$PICKED"
fi
exit;;
*)
PICKED=$(pick --percol <<<"$PICKED");;
esac
done