summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPmoranga <pmoranga@users.noreply.github.com>2019-04-09 22:41:36 +0200
committerMarc Cornellà <marc.cornella@live.com>2019-04-09 22:41:36 +0200
commitd36c1b8d227d49c460e6664118bd42f522b361ca (patch)
tree00f59ca7a2343ff217ea6ec4533cb442cf3578bd
parent0c3499ecd9cdd562ae88fa4b33db97311a78cb07 (diff)
downloadzsh-d36c1b8d227d49c460e6664118bd42f522b361ca.tar.gz
zsh-d36c1b8d227d49c460e6664118bd42f522b361ca.tar.bz2
zsh-d36c1b8d227d49c460e6664118bd42f522b361ca.zip
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
-rw-r--r--plugins/kube-ps1/README.md28
-rw-r--r--plugins/kube-ps1/kube-ps1.plugin.zsh28
2 files changed, 45 insertions, 11 deletions
diff --git a/plugins/kube-ps1/README.md b/plugins/kube-ps1/README.md
index fcb73cd2d..19dac42e9 100644
--- a/plugins/kube-ps1/README.md
+++ b/plugins/kube-ps1/README.md
@@ -45,20 +45,37 @@ want to load.
vim $HOME/.zshrc
```
-Add kube-ps1 to the list of enabled plugins:
+Add kube-ps1 to the list of enabled plugins and enable it on the prompt:
```shell
plugins=(
git
kube-ps1
)
+
+PROMPT=$PROMPT'$(kube_ps1) '
+```
+
+Note: the `PROMPT` example above was tested with the theme `robbyrussell`
+
+## Enabling / Disabling on the current shell
+
+Sometimes the kubernetes information can be anoying, you can easily
+switch it on and off with the following commands:
+
+```shell
+kubeon
+```
+
+```shell
+kubeoff
```
## Colors
Blue was used as the prefix to match the Kubernetes color as closely as
possible. Red was chosen as the cluster name to stand out, and cyan
-for the namespace. These can of course be changed.
+for the namespace. Check the customization section for changing them.
## Customization
@@ -75,7 +92,12 @@ The default settings can be overridden in ~/.zshrc
| `KUBE_PS1_SEPERATOR` | `\|` | Separator between symbol and cluster name |
| `KUBE_PS1_DIVIDER` | `:` | Separator between cluster and namespace |
| `KUBE_PS1_SUFFIX` | `)` | Prompt closing character |
+| `KUBE_PS1_COLOR_SYMBOL` | `"%F{blue}"` | Custom color for the symbol |
+| `KUBE_PS1_COLOR_CONTEXT` | `"%F{red}"` | Custom color for the context |
+| `KUBE_PS1_COLOR_NS` | `"%F{cyan}"` | Custom color for the namespace |
+| `KUBE_PS1_ENABLED` | `true` | Set to false to start disabled on any new shell, `kubeon`/`kubeoff` will flip this value on the current shell |
## Contributors
-Jared Yanovich
+- Jared Yanovich
+- Pedro Moranga \ No newline at end of file
diff --git a/plugins/kube-ps1/kube-ps1.plugin.zsh b/plugins/kube-ps1/kube-ps1.plugin.zsh
index df7277a26..8a751bda8 100644
--- a/plugins/kube-ps1/kube-ps1.plugin.zsh
+++ b/plugins/kube-ps1/kube-ps1.plugin.zsh
@@ -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}"
-
}