@@ -2,7 +2,7 @@ setopt prompt_subst
2
2
autoload -U add-zsh-hook
3
3
4
4
function () {
5
- local namespace separator modified_time_fmt
5
+ local namespace separator binary
6
6
7
7
# Specify the separator between context and namespace
8
8
zstyle -s ' :zsh-kubectl-prompt:' separator separator
@@ -15,11 +15,23 @@ function() {
15
15
if [[ -z " $namespace " ]]; then
16
16
zstyle ' :zsh-kubectl-prompt:' namespace true
17
17
fi
18
+
19
+ # Specify the binary to get the information from kubeconfig (e.g. `oc`)
20
+ zstyle -s ' :zsh-kubectl-binary:' binary binary
21
+ if [[ -z " $binary " ]]; then
22
+ zstyle ' :zsh-kubectl-prompt:' binary " kubectl"
23
+ fi
18
24
}
19
25
20
26
add-zsh-hook precmd _zsh_kubectl_prompt_precmd
21
27
function _zsh_kubectl_prompt_precmd() {
22
- local kubeconfig config updated_at now context namespace ns separator modified_time_fmt
28
+ local kubeconfig config updated_at now context namespace ns separator modified_time_fmt binary
29
+
30
+ zstyle -s ' :zsh-kubectl-prompt:' binary binary
31
+ if ! command -v " $binary " > /dev/null; then
32
+ ZSH_KUBECTL_PROMPT=" ${binary} command not found"
33
+ return 1
34
+ fi
23
35
24
36
kubeconfig=" $HOME /.kube/config"
25
37
if [[ -n " $KUBECONFIG " ]]; then
@@ -53,14 +65,14 @@ function _zsh_kubectl_prompt_precmd() {
53
65
zstyle ' :zsh-kubectl-prompt:' updated_at " $now "
54
66
55
67
# Set environment variable if context is not set
56
- if ! context=" $( kubectl config current-context 2> /dev/null) " ; then
68
+ if ! context=" $( " $binary " config current-context 2> /dev/null) " ; then
57
69
ZSH_KUBECTL_PROMPT=" current-context is not set"
58
70
return 1
59
71
fi
60
72
61
- ZSH_KUBECTL_USER=" $( kubectl config view -o " jsonpath={.contexts[?(@.name==\" $context \" )].context.user}" ) "
73
+ ZSH_KUBECTL_USER=" $( " $binary " config view -o " jsonpath={.contexts[?(@.name==\" $context \" )].context.user}" ) "
62
74
ZSH_KUBECTL_CONTEXT=" ${context} "
63
- ns=" $( kubectl config view -o " jsonpath={.contexts[?(@.name==\" $context \" )].context.namespace}" ) "
75
+ ns=" $( " $binary " config view -o " jsonpath={.contexts[?(@.name==\" $context \" )].context.namespace}" ) "
64
76
[[ -z " $ns " ]] && ns=" default"
65
77
ZSH_KUBECTL_NAMESPACE=" ${ns} "
66
78
0 commit comments