mirror of
https://github.com/romkatv/powerlevel10k.git
synced 2024-12-21 06:41:57 +00:00
add POWERLEVEL9K_KUBECONTEXT_CLASSES
This commit is contained in:
parent
b8b197ec17
commit
e3890f2ec6
1 changed files with 42 additions and 2 deletions
|
@ -2057,7 +2057,35 @@ prompt_dir_writable() {
|
||||||
|
|
||||||
################################################################
|
################################################################
|
||||||
# Kubernetes Current Context/Namespace
|
# Kubernetes Current Context/Namespace
|
||||||
|
|
||||||
|
# Set to false to truncate trailing "/default": "mycontext/default" will become "mycontext".
|
||||||
set_default POWERLEVEL9K_KUBECONTEXT_SHOW_DEFAULT_NAMESPACE true
|
set_default POWERLEVEL9K_KUBECONTEXT_SHOW_DEFAULT_NAMESPACE true
|
||||||
|
|
||||||
|
# Defines context classes for the purpose of applying different styling to different contexts.
|
||||||
|
#
|
||||||
|
# POWERLEVEL9K_KUBECONTEXT_CLASSES must be an array with even number of elements. The first
|
||||||
|
# element in each pair defines a pattern against which the current context (in the format it is
|
||||||
|
# displayed in the prompt) gets matched. The second element defines context class. Patterns are
|
||||||
|
# tried in order. The first match wins.
|
||||||
|
#
|
||||||
|
# If a non-empty class <C> is assigned to a context, the segment is styled with
|
||||||
|
# POWERLEVEL9K_KUBECONTEXT_<U>_BACKGROUND and POWERLEVEL9K_KUBECONTEXT_<U>_FOREGROUND where <U> is
|
||||||
|
# uppercased <C>. Otherwise with POWERLEVEL9K_KUBECONTEXT_BACKGROUND and
|
||||||
|
# POWERLEVEL9K_KUBECONTEXT_FOREGROUND.
|
||||||
|
#
|
||||||
|
# Example: Use red background for contexts containing "prod", green for "testing" and yellow for
|
||||||
|
# everything else.
|
||||||
|
#
|
||||||
|
# POWERLEVEL9K_KUBECONTEXT_CLASSES=(
|
||||||
|
# '*prod*' prod
|
||||||
|
# '*testing*' testing
|
||||||
|
# '*' other)
|
||||||
|
#
|
||||||
|
# POWERLEVEL9K_KUBECONTEXT_PROD_BACKGROUND=red
|
||||||
|
# POWERLEVEL9K_KUBECONTEXT_TESTING_BACKGROUND=green
|
||||||
|
# POWERLEVEL9K_KUBECONTEXT_OTHER_BACKGROUND=yellow
|
||||||
|
set_default -a POWERLEVEL9K_KUBECONTEXT_CLASSES
|
||||||
|
|
||||||
prompt_kubecontext() {
|
prompt_kubecontext() {
|
||||||
(( $+commands[kubectl] )) || return
|
(( $+commands[kubectl] )) || return
|
||||||
local cfg
|
local cfg
|
||||||
|
@ -2067,6 +2095,7 @@ prompt_kubecontext() {
|
||||||
zstat -H stat -- $cfg 2>/dev/null || continue
|
zstat -H stat -- $cfg 2>/dev/null || continue
|
||||||
key+=($cfg $stat[inode] $stat[mtime] $stat[size] $stat[mode])
|
key+=($cfg $stat[inode] $stat[mtime] $stat[size] $stat[mode])
|
||||||
done
|
done
|
||||||
|
|
||||||
if ! _p9k_cache_get $0 "${key[@]}"; then
|
if ! _p9k_cache_get $0 "${key[@]}"; then
|
||||||
local ctx=$(command kubectl config view -o=jsonpath='{.current-context}')
|
local ctx=$(command kubectl config view -o=jsonpath='{.current-context}')
|
||||||
if [[ -n $ctx ]]; then
|
if [[ -n $ctx ]]; then
|
||||||
|
@ -2076,10 +2105,21 @@ prompt_kubecontext() {
|
||||||
ctx+="/$ns"
|
ctx+="/$ns"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
_p9k_cache_set "$ctx"
|
local suf
|
||||||
|
if [[ -n $ctx ]]; then
|
||||||
|
local pat class
|
||||||
|
for pat class in $POWERLEVEL9K_KUBECONTEXT_CLASSES; do
|
||||||
|
if [[ $ctx == ${~pat} ]]; then
|
||||||
|
[[ -n $class ]] && suf=_${(U)class}
|
||||||
|
break
|
||||||
fi
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
_p9k_cache_set "$ctx" "$suf"
|
||||||
|
fi
|
||||||
|
|
||||||
[[ -n $_P9K_CACHE_VAL[1] ]] || return
|
[[ -n $_P9K_CACHE_VAL[1] ]] || return
|
||||||
$1_prompt_segment $0 $2 magenta white KUBERNETES_ICON 0 '' "${_P9K_CACHE_VAL[1]//\%/%%}"
|
$1_prompt_segment $0$_P9K_CACHE_VAL[2] $2 magenta white KUBERNETES_ICON 0 '' "${_P9K_CACHE_VAL[1]//\%/%%}"
|
||||||
}
|
}
|
||||||
|
|
||||||
################################################################
|
################################################################
|
||||||
|
|
Loading…
Reference in a new issue