forked from kubernetian/KUBECONFIGSWITCHER9000
-
Notifications
You must be signed in to change notification settings - Fork 0
/
KCS9
executable file
·39 lines (34 loc) · 769 Bytes
/
KCS9
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
#!/bin/bash
# Parse parameters asvariables
while [ $# -gt 0 ]; do
if [[ $1 == *"--"* ]]; then
v="${1/--/}"
declare $v="${1/--/}"
fi
shift
done
PS3="Which config do you want to use? "
rm -rf ~/.kube/config
files=($(ls ~/.kube))
selectfiles=()
for file in "${files[@]}"
do
if [[ -f ~/.kube/$file ]]; then
line=$(head -n 1 ~/.kube/$file)
if [[ $line = "apiVersion: v1" ]]; then
selectfiles+=($file)
fi
fi
done
if [[ -z "$fzf" ]]
then
select file in "${selectfiles[@]}"
do
echo "Selected config: $file"
cp ~/.kube/$file ~/.kube/config
exit 1
done
else
file=$(printf "%s\n" "${selectfiles[@]}" | fzf --ansi --height=50% --reverse --inline-info --border)
cp ~/.kube/$file ~/.kube/config
fi