add P9K_KUBECONTEXT_USER

This commit is contained in:
romkatv 2020-01-26 11:45:56 +01:00
parent 9c21f4b273
commit 5e42c4c930
5 changed files with 20 additions and 8 deletions

View File

@ -865,6 +865,8 @@
# - P9K_KUBECONTEXT_NAMESPACE The current context's namespace. Corresponds to column NAMESPACE
# in the output of `kubectl config get-contexts`. If there is no
# namespace, the parameter is set to "default".
# - P9K_KUBECONTEXT_USER The current context's user. Corresponds to column AUTHINFO in the
# output of `kubectl config get-contexts`.
#
# If the context points to Google Kubernetes Engine (GKE) or Elastic Kubernetes Service (EKS),
# the following extra parameters are available:

View File

@ -838,6 +838,8 @@
# - P9K_KUBECONTEXT_NAMESPACE The current context's namespace. Corresponds to column NAMESPACE
# in the output of `kubectl config get-contexts`. If there is no
# namespace, the parameter is set to "default".
# - P9K_KUBECONTEXT_USER The current context's user. Corresponds to column AUTHINFO in the
# output of `kubectl config get-contexts`.
#
# If the context points to Google Kubernetes Engine (GKE) or Elastic Kubernetes Service (EKS),
# the following extra parameters are available:

View File

@ -838,6 +838,8 @@
# - P9K_KUBECONTEXT_NAMESPACE The current context's namespace. Corresponds to column NAMESPACE
# in the output of `kubectl config get-contexts`. If there is no
# namespace, the parameter is set to "default".
# - P9K_KUBECONTEXT_USER The current context's user. Corresponds to column AUTHINFO in the
# output of `kubectl config get-contexts`.
#
# If the context points to Google Kubernetes Engine (GKE) or Elastic Kubernetes Service (EKS),
# the following extra parameters are available:

View File

@ -897,6 +897,8 @@
# - P9K_KUBECONTEXT_NAMESPACE The current context's namespace. Corresponds to column NAMESPACE
# in the output of `kubectl config get-contexts`. If there is no
# namespace, the parameter is set to "default".
# - P9K_KUBECONTEXT_USER The current context's user. Corresponds to column AUTHINFO in the
# output of `kubectl config get-contexts`.
#
# If the context points to Google Kubernetes Engine (GKE) or Elastic Kubernetes Service (EKS),
# the following extra parameters are available:

View File

@ -3836,7 +3836,8 @@ prompt_kubecontext() {
(( $+commands[kubectl] )) || return
if ! _p9k_cache_stat_get $0 ${(s.:.)${KUBECONFIG:-$HOME/.kube/config}}; then
local name namespace cluster 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 -a match
() {
local cfg && cfg=(${(f)"$(kubectl config view -o=yaml 2>/dev/null)"}) || return
local ctx=(${(@M)cfg:#current-context: [^\"\'\|\>]*})
@ -3856,6 +3857,8 @@ prompt_kubecontext() {
cluster=$match[1]
elif [[ $line == (#b)' namespace: '([^\"\'\|\>]*) ]]; then
namespace=$match[1]
elif [[ $line == (#b)' user: '([^\"\'\|\>]*) ]]; then
user=$match[1]
fi
done
}
@ -3895,18 +3898,19 @@ prompt_kubecontext() {
fi
done
fi
_p9k_cache_stat_set "$name" "$namespace" "$cluster" "$cloud_name" "$cloud_account" "$cloud_zone" "$cloud_cluster" "$text" "$state"
_p9k_cache_stat_set "$name" "$namespace" "$cluster" "$user" "$cloud_name" "$cloud_account" "$cloud_zone" "$cloud_cluster" "$text" "$state"
fi
typeset -g P9K_KUBECONTEXT_NAME=$_p9k_cache_val[1]
typeset -g P9K_KUBECONTEXT_NAMESPACE=$_p9k_cache_val[2]
typeset -g P9K_KUBECONTEXT_CLUSTER=$_p9k_cache_val[3]
typeset -g P9K_KUBECONTEXT_CLOUD_NAME=$_p9k_cache_val[4]
typeset -g P9K_KUBECONTEXT_CLOUD_ACCOUNT=$_p9k_cache_val[5]
typeset -g P9K_KUBECONTEXT_CLOUD_ZONE=$_p9k_cache_val[6]
typeset -g P9K_KUBECONTEXT_CLOUD_CLUSTER=$_p9k_cache_val[7]
[[ -n $_p9k_cache_val[8] ]] || return
_p9k_prompt_segment $0$_p9k_cache_val[9] magenta white KUBERNETES_ICON 0 '' "${_p9k_cache_val[8]//\%/%%}"
typeset -g P9K_KUBECONTEXT_USER=$_p9k_cache_val[4]
typeset -g P9K_KUBECONTEXT_CLOUD_NAME=$_p9k_cache_val[5]
typeset -g P9K_KUBECONTEXT_CLOUD_ACCOUNT=$_p9k_cache_val[6]
typeset -g P9K_KUBECONTEXT_CLOUD_ZONE=$_p9k_cache_val[7]
typeset -g P9K_KUBECONTEXT_CLOUD_CLUSTER=$_p9k_cache_val[8]
[[ -n $_p9k_cache_val[9] ]] || return
_p9k_prompt_segment $0$_p9k_cache_val[10] magenta white KUBERNETES_ICON 0 '' "${_p9k_cache_val[9]//\%/%%}"
}
_p9k_prompt_kubecontext_init() {