mirror of
https://github.com/romkatv/powerlevel10k.git
synced 2024-12-18 21:41:57 +00:00
kubecontext: handle strings with spaces and ignore multi-line strings
This commit is contained in:
parent
2318bda2c3
commit
05deaa802f
1 changed files with 10 additions and 8 deletions
|
@ -2896,10 +2896,10 @@ prompt_kubecontext() {
|
||||||
if ! _p9k_cache_get $0 "${key[@]}"; then
|
if ! _p9k_cache_get $0 "${key[@]}"; then
|
||||||
local context cluster namespace
|
local context cluster namespace
|
||||||
() {
|
() {
|
||||||
local cfg && cfg=(${(f)"$(kubectl config view -o=yaml)"}) || return
|
local cfg && cfg=(${(f)"$(kubectl config view -o=yaml 2>/dev/null)"}) || return
|
||||||
local ctx=(${(@M)cfg:#current-context:[[:space:]]*})
|
local ctx=(${(@M)cfg:#current-context: [^\"\'|>]*})
|
||||||
(( $#ctx == 1 )) || return
|
(( $#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:]}
|
local -i pos=${cfg[(i)contexts:]}
|
||||||
(( pos <= $#cfg )) || return
|
(( pos <= $#cfg )) || return
|
||||||
shift $pos cfg
|
shift $pos cfg
|
||||||
|
@ -2908,11 +2908,13 @@ prompt_kubecontext() {
|
||||||
(( --pos ))
|
(( --pos ))
|
||||||
for ((; pos > 0; --pos)); do
|
for ((; pos > 0; --pos)); do
|
||||||
local line=$cfg[pos]
|
local line=$cfg[pos]
|
||||||
case $line in
|
if [[ $line == '- context:' ]]; then
|
||||||
'- context:') return;;
|
return
|
||||||
' cluster:'*) cluster=${line[(w)2]};;
|
elif [[ $line == (#b)' cluster: '([^\"\'\|\>]*) ]]; then
|
||||||
' namespace:'*) namespace=${line[(w)2]};;
|
cluster=$match[1]
|
||||||
esac
|
elif [[ $line == (#b)' namespace: '([^\"\'\|\>]*) ]]; then
|
||||||
|
namespace=$match[1]
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
local text=$context
|
local text=$context
|
||||||
|
|
Loading…
Reference in a new issue