1
0
mirror of https://github.com/robbyrussell/oh-my-zsh.git synced 2025-12-07 07:50:40 +01:00

kube_ps1: customize colors and dynamically toggle prompt (#7269)

changes:
- easily customize the colors via variables
- command to switch on/off the custom prompt
- Improved documentation with example on how to append on the prompt.

Fixes #7261
This commit is contained in:
Pmoranga
2019-04-09 22:41:36 +02:00
committed by Marc Cornellà
parent 0c3499ecd9
commit d36c1b8d22
2 changed files with 45 additions and 11 deletions

View File

@@ -39,6 +39,11 @@ KUBE_PS1_DIVIDER="${KUBE_PS1_DIVIDER-:}"
KUBE_PS1_PREFIX="${KUBE_PS1_PREFIX-(}"
KUBE_PS1_SUFFIX="${KUBE_PS1_SUFFIX-)}"
KUBE_PS1_LAST_TIME=0
KUBE_PS1_ENABLED=true
KUBE_PS1_COLOR_SYMBOL="%F{blue}"
KUBE_PS1_COLOR_CONTEXT="%F{red}"
KUBE_PS1_COLOR_NS="%F{cyan}"
_kube_ps1_binary_check() {
command -v "$1" >/dev/null
@@ -127,21 +132,28 @@ _kube_ps1_get_context_ns() {
fi
}
# function to disable the prompt on the current shell
kubeon(){
KUBE_PS1_ENABLED=true
}
# function to disable the prompt on the current shell
kubeoff(){
KUBE_PS1_ENABLED=false
}
# Build our prompt
kube_ps1 () {
local reset_color="%f"
local blue="%F{blue}"
local red="%F{red}"
local cyan="%F{cyan}"
local reset_color="%{$reset_color%}"
[[ ${KUBE_PS1_ENABLED} != 'true' ]] && return
KUBE_PS1="${reset_color}$KUBE_PS1_PREFIX"
KUBE_PS1+="${blue}$(_kube_ps1_symbol)"
KUBE_PS1+="${KUBE_PS1_COLOR_SYMBOL}$(_kube_ps1_symbol)"
KUBE_PS1+="${reset_color}$KUBE_PS1_SEPERATOR"
KUBE_PS1+="${red}$KUBE_PS1_CONTEXT${reset_color}"
KUBE_PS1+="${KUBE_PS1_COLOR_CONTEXT}$KUBE_PS1_CONTEXT${reset_color}"
KUBE_PS1+="$KUBE_PS1_DIVIDER"
KUBE_PS1+="${cyan}$KUBE_PS1_NAMESPACE${reset_color}"
KUBE_PS1+="${KUBE_PS1_COLOR_NS}$KUBE_PS1_NAMESPACE${reset_color}"
KUBE_PS1+="$KUBE_PS1_SUFFIX"
echo "${KUBE_PS1}"
}