summaryrefslogtreecommitdiff
path: root/plugins/kubectx
diff options
context:
space:
mode:
authorTuowen Zhao <ztuowen@gmail.com>2022-02-19 17:12:23 -0600
committerTuowen Zhao <ztuowen@gmail.com>2022-02-19 17:12:23 -0600
commitcae9a2b797649379e865e6bd73bc67e294e4ac77 (patch)
tree481419eff4bc761c3ca516704427394193473419 /plugins/kubectx
parent49edbf438ed690c76e6b2af80368c59404cf0167 (diff)
parent3427da4057dbe302933a7b5b19b4e23bfb9d0969 (diff)
downloadzsh-cae9a2b797649379e865e6bd73bc67e294e4ac77.tar.gz
zsh-cae9a2b797649379e865e6bd73bc67e294e4ac77.tar.bz2
zsh-cae9a2b797649379e865e6bd73bc67e294e4ac77.zip
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'plugins/kubectx')
-rw-r--r--plugins/kubectx/kubectx.plugin.zsh16
1 files changed, 10 insertions, 6 deletions
diff --git a/plugins/kubectx/kubectx.plugin.zsh b/plugins/kubectx/kubectx.plugin.zsh
index abbdc254b..6096feeae 100644
--- a/plugins/kubectx/kubectx.plugin.zsh
+++ b/plugins/kubectx/kubectx.plugin.zsh
@@ -1,9 +1,13 @@
-typeset -A kubectx_mapping
+typeset -g -A kubectx_mapping
function kubectx_prompt_info() {
- if [ $commands[kubectl] ]; then
- local current_ctx=`kubectl config current-context`
- # use value in associative array if it exists, otherwise fall back to the context name
- echo "${kubectx_mapping[$current_ctx]:-$current_ctx}"
- fi
+ (( $+commands[kubectl] )) || return
+
+ local current_ctx=$(kubectl config current-context 2> /dev/null)
+
+ [[ -n "$current_ctx" ]] || return
+
+ # use value in associative array if it exists
+ # otherwise fall back to the context name
+ echo "${kubectx_mapping[$current_ctx]:-${current_ctx:gs/%/%%}}"
}