-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlib.kube
More file actions
49 lines (37 loc) · 1 KB
/
lib.kube
File metadata and controls
49 lines (37 loc) · 1 KB
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
#!/bin/bash
export KUBE_PROMPT_ENABLED=0
function __kube_update_config() {
local l_base
l_base="$(find ~/.kube/ -maxdepth 1 -type f -not -name config | tr "\n" ":")"
export KUBECONFIG="${l_base}${HOME}/.kube/config"
}
function __kube_update_labels() {
test ${KUBE_PROMPT_ENABLED} -eq 0 && {
return 0
}
local l_ctx
local l_color="26"
l_ctx=$(kubectl config current-context) || {
return 0
}
test ! -f ~/.kube/config && {
return 0
}
# local l_ctx=$(cat ~/.kube/config | yq .current-context | sed -e 's/-dp//' -e 's/-aks//' -e 's/-kind//')
if [[ "${l_ctx}" == *prd* ]]; then
l_color="199"
elif [[ "${l_ctx}" == *stg* ]]; then
l_color="172"
elif [[ "${l_ctx}" == *sbx* ]]; then
l_color="79"
fi
promptcmd_add_labels "k8s⌈${l_ctx}⌉|${l_color}"
}
function kube_enable_prompt() {
KUBE_PROMPT_ENABLED=1
promptcmd_push "__kube_update_labels"
promptcmd_push "__kube_update_config"
}
function kube_disable_prompt() {
KUBE_PROMPT_ENABLED=0
}