aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorromkatv <roman.perepelitsa@gmail.com>2019-07-30 08:52:26 +0300
committerromkatv <roman.perepelitsa@gmail.com>2019-07-30 08:52:26 +0300
commit05deaa802f67c0c9001ea9f1cd3ae0f078de5f06 (patch)
tree9903d628a5c8bd7cc11073120b923c80c802a022
parent2318bda2c31f687d2c9c0c6ee0a1dea07b4d13f4 (diff)
kubecontext: handle strings with spaces and ignore multi-line strings
-rwxr-xr-xinternal/p10k.zsh18
1 files changed, 10 insertions, 8 deletions
diff --git a/internal/p10k.zsh b/internal/p10k.zsh
index b76fa7ae..67fc4b16 100755
--- a/internal/p10k.zsh
+++ b/internal/p10k.zsh
@@ -2896,10 +2896,10 @@ prompt_kubecontext() {
if ! _p9k_cache_get $0 "${key[@]}"; then
local context cluster namespace
() {
- local cfg && cfg=(${(f)"$(kubectl config view -o=yaml)"}) || return
- local ctx=(${(@M)cfg:#current-context:[[:space:]]*})
+ local cfg && cfg=(${(f)"$(kubectl config view -o=yaml 2>/dev/null)"}) || return
+ local ctx=(${(@M)cfg:#current-context: [^\"\'|>]*})
(( $#ctx == 1 )) || return
- context=${${ctx[1]}[(w)2]} # TODO: figure out how values with spaces look in yaml
+ context=${ctx[1]#current-context: }
local -i pos=${cfg[(i)contexts:]}
(( pos <= $#cfg )) || return
shift $pos cfg
@@ -2908,11 +2908,13 @@ prompt_kubecontext() {
(( --pos ))
for ((; pos > 0; --pos)); do
local line=$cfg[pos]
- case $line in
- '- context:') return;;
- ' cluster:'*) cluster=${line[(w)2]};;
- ' namespace:'*) namespace=${line[(w)2]};;
- esac
+ if [[ $line == '- context:' ]]; then
+ return
+ elif [[ $line == (#b)' cluster: '([^\"\'\|\>]*) ]]; then
+ cluster=$match[1]
+ elif [[ $line == (#b)' namespace: '([^\"\'\|\>]*) ]]; then
+ namespace=$match[1]
+ fi
done
}
local text=$context