-
Notifications
You must be signed in to change notification settings - Fork 0
/
__kube_prompt.fish.custom.example1
62 lines (51 loc) · 1.76 KB
/
__kube_prompt.fish.custom.example1
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
# Inspired from:
# https://github.com/jonmosco/kube-ps1
# https://github.com/Ladicle/fish-kubectl-prompt
set -g color_blue (set_color blue)
set -g color_red (set_color DF4F2B)
set -g color_green (set_color green)
function __kube_ps_update_cache
function __kube_ps_cache_namespace
set -l ns (kubectl config view --minify -o 'jsonpath={..namespace}' 2>/dev/null)
set -l ctx (kubectl config current-context)
if string match -q "$ctx" "kind-k122"
set -g __kube_ps_namespace "$color_green$ns"
return
end
set -g __kube_ps_context "$color_red$ctx"
set -g __kube_ps_namespace "$color_blue$ns"
end
function __stat_mtime
#-- cross-platform workaround; POSIX didn't specify stat(1) and so
#-- its interface is incompatibly different on Mac OS and Linux.
#-- see https://unix.stackexchange.com/q/561927/3097
python3 -c "print(__import__('os').stat(__import__('sys').argv[1]).st_mtime)" $argv
end
set -l kubeconfig "$KUBECONFIG"
if test -z "$kubeconfig"
set kubeconfig "$HOME/.kube/config"
end
if test "$kubeconfig" != "$__kube_ps_kubeconfig"
__kube_ps_cache_namespace
set -g __kube_ps_kubeconfig "$kubeconfig"
set -g __kube_ps_timestamp (date +%s)
return
end
for conf in (string split ':' "$kubeconfig")
if test -r "$conf"
if test -z "$__kube_ps_timestamp"; or test (__stat_mtime "$conf") -gt "$__kube_ps_timestamp"
__kube_ps_cache_namespace
set -g __kube_ps_kubeconfig "$kubeconfig"
set -g __kube_ps_timestamp (date +%s)
return
end
end
end
end
function __kube_prompt
if test -z "$__kube_ps_enabled"; or test $__kube_ps_enabled -ne 1
return
end
__kube_ps_update_cache
echo -n -s " (⎈ $__kube_ps_context|$__kube_ps_namespace)"
end