1
0
Fork 0
mirror of https://github.com/romkatv/powerlevel10k.git synced 2024-11-25 13:30:07 +00:00

recognize double-quoted strings when parsing kube configs; other types of quotes are still not supported; see #1061

This commit is contained in:
Roman Perepelitsa 2020-10-21 13:39:56 +02:00
parent e43209409b
commit 47713ea2df

View file

@ -4306,27 +4306,36 @@ prompt_kubecontext() {
local name namespace cluster user cloud_name cloud_account cloud_zone cloud_cluster text state 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 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 (( $#ctx == 1 )) || return
name=${ctx[1]#current-context: } name=${ctx[1]#current-context: }
local -i pos=${cfg[(i)contexts:]} local -i pos=${cfg[(i)contexts:]}
(( pos <= $#cfg )) || return {
shift $pos cfg (( pos <= $#cfg )) || return
pos=${cfg[(i) name: $name]} shift $pos cfg
(( pos <= $#cfg )) || return pos=${cfg[(i) name: $name]}
(( --pos )) (( pos <= $#cfg )) || return
for ((; pos > 0; --pos)); do (( --pos ))
local line=$cfg[pos] for ((; pos > 0; --pos)); do
if [[ $line == '- context:' ]]; then local line=$cfg[pos]
return 0 if [[ $line == '- context:' ]]; then
elif [[ $line == (#b)' cluster: '([^\"\'\|\>]*) ]]; then return 0
cluster=$match[1] elif [[ $line == (#b)' cluster: '($~str) ]]; then
elif [[ $line == (#b)' namespace: '([^\"\'\|\>]*) ]]; then cluster=$match[1]
namespace=$match[1] [[ $cluster == $~qstr ]] && cluster=$cluster[2,-2]
elif [[ $line == (#b)' user: '([^\"\'\|\>]*) ]]; then elif [[ $line == (#b)' namespace: '($~str) ]]; then
user=$match[1] namespace=$match[1]
fi [[ $namespace == $~qstr ]] && namespace=$namespace[2,-2]
done 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 if [[ -n $name ]]; then
: ${namespace:=default} : ${namespace:=default}