summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Perepelitsa <roman.perepelitsa@gmail.com>2020-10-21 14:39:56 +0300
committerRoman Perepelitsa <roman.perepelitsa@gmail.com>2020-10-21 14:40:10 +0300
commit47713ea2df0c467f950a065b27182ac685c33dae (patch)
tree712f2dc75abe99bd9c5ae3002fb5e7e1947dffd1
parente43209409b585c3b26e1c9a3fa1d90b19c9fe484 (diff)
recognize double-quoted strings when parsing kube configs; other types of quotes are still not supported; see #1061
-rw-r--r--internal/p10k.zsh45
1 files changed, 27 insertions, 18 deletions
diff --git a/internal/p10k.zsh b/internal/p10k.zsh
index 1626c59f..f67574af 100644
--- a/internal/p10k.zsh
+++ b/internal/p10k.zsh
@@ -4306,27 +4306,36 @@ prompt_kubecontext() {
local name namespace cluster user cloud_name cloud_account cloud_zone cloud_cluster text state
() {
local cfg && cfg=(${(f)"$(kubectl config view -o=yaml 2>/dev/null)"}) || return
- local ctx=(${(@M)cfg:#current-context: [^\"\'\|\>]*})
+ local qstr='"*"'
+ local str='([^"'\''|>]*|'$qstr')'
+ local ctx=(${(@M)cfg:#current-context: $~str})
(( $#ctx == 1 )) || return
name=${ctx[1]#current-context: }
local -i pos=${cfg[(i)contexts:]}
- (( pos <= $#cfg )) || return
- shift $pos cfg
- pos=${cfg[(i) name: $name]}
- (( pos <= $#cfg )) || return
- (( --pos ))
- for ((; pos > 0; --pos)); do
- local line=$cfg[pos]
- if [[ $line == '- context:' ]]; then
- return 0
- elif [[ $line == (#b)' cluster: '([^\"\'\|\>]*) ]]; then
- cluster=$match[1]
- elif [[ $line == (#b)' namespace: '([^\"\'\|\>]*) ]]; then
- namespace=$match[1]
- elif [[ $line == (#b)' user: '([^\"\'\|\>]*) ]]; then
- user=$match[1]
- fi
- done
+ {
+ (( pos <= $#cfg )) || return
+ shift $pos cfg
+ pos=${cfg[(i) name: $name]}
+ (( pos <= $#cfg )) || return
+ (( --pos ))
+ for ((; pos > 0; --pos)); do
+ local line=$cfg[pos]
+ if [[ $line == '- context:' ]]; then
+ return 0
+ elif [[ $line == (#b)' cluster: '($~str) ]]; then
+ cluster=$match[1]
+ [[ $cluster == $~qstr ]] && cluster=$cluster[2,-2]
+ elif [[ $line == (#b)' namespace: '($~str) ]]; then
+ namespace=$match[1]
+ [[ $namespace == $~qstr ]] && namespace=$namespace[2,-2]
+ elif [[ $line == (#b)' user: '($~str) ]]; then
+ user=$match[1]
+ [[ $user == $~qstr ]] && user=$user[2,-2]
+ fi
+ done
+ } always {
+ [[ $name == $~qstr ]] && name=$name[2,-2]
+ }
}
if [[ -n $name ]]; then
: ${namespace:=default}