From d87ab251c7fe18626b2d0c4e4a184e7bed7c508b Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Mon, 3 Jan 2022 14:03:36 +0100 Subject: fix(kubectx): quote % in `kubectx_prompt_info` --- plugins/kubectx/kubectx.plugin.zsh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'plugins/kubectx') diff --git a/plugins/kubectx/kubectx.plugin.zsh b/plugins/kubectx/kubectx.plugin.zsh index abbdc254b..af9a17ef1 100644 --- a/plugins/kubectx/kubectx.plugin.zsh +++ b/plugins/kubectx/kubectx.plugin.zsh @@ -1,9 +1,11 @@ typeset -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) + + # use value in associative array if it exists + # otherwise fall back to the context name + echo "${${kubectx_mapping[$current_ctx]:-$current_ctx}:gs/%/%%}" } -- cgit v1.2.3-70-g09d2 From 31d63ea884e8ef56a40bed8771cdd8d3aec131f9 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Tue, 4 Jan 2022 11:38:53 +0100 Subject: fix(kubectx): allow prompt sequences in `kubectx_mapping` (#10562) Fixes #10562 --- plugins/kubectx/kubectx.plugin.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'plugins/kubectx') diff --git a/plugins/kubectx/kubectx.plugin.zsh b/plugins/kubectx/kubectx.plugin.zsh index af9a17ef1..1419f102f 100644 --- a/plugins/kubectx/kubectx.plugin.zsh +++ b/plugins/kubectx/kubectx.plugin.zsh @@ -1,4 +1,4 @@ -typeset -A kubectx_mapping +typeset -g -A kubectx_mapping function kubectx_prompt_info() { (( $+commands[kubectl] )) || return @@ -7,5 +7,5 @@ function kubectx_prompt_info() { # use value in associative array if it exists # otherwise fall back to the context name - echo "${${kubectx_mapping[$current_ctx]:-$current_ctx}:gs/%/%%}" + echo "${kubectx_mapping[$current_ctx]:-${current_ctx:gs/%/%%}}" } -- cgit v1.2.3-70-g09d2 From 6396dfb97f13f5fbb0ef98cd5221600b89ff889a Mon Sep 17 00:00:00 2001 From: Sam Cook Date: Thu, 10 Feb 2022 16:00:45 +0000 Subject: fix(kubectx): don't error on missing k8s context (#10675) --- plugins/kubectx/kubectx.plugin.zsh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'plugins/kubectx') diff --git a/plugins/kubectx/kubectx.plugin.zsh b/plugins/kubectx/kubectx.plugin.zsh index 1419f102f..6096feeae 100644 --- a/plugins/kubectx/kubectx.plugin.zsh +++ b/plugins/kubectx/kubectx.plugin.zsh @@ -3,7 +3,9 @@ typeset -g -A kubectx_mapping function kubectx_prompt_info() { (( $+commands[kubectl] )) || return - local current_ctx=$(kubectl config current-context) + 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 -- cgit v1.2.3-70-g09d2