From e8db205e6f772a8e46aaedc6875c74c8d157a1c2 Mon Sep 17 00:00:00 2001 From: Kazuki Suda Date: Tue, 3 Nov 2020 16:08:01 +0900 Subject: [PATCH] Update custom color depending on context In README.md example, the color does not change when the value of the variable is changed. --- README.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2492379..506908e 100644 --- a/README.md +++ b/README.md @@ -25,8 +25,16 @@ For example, make the prompt red when the username matches admin. ```sh autoload -U colors; colors source /path/to/zsh-kubectl-prompt/kubectl.zsh -[[ "$ZSH_KUBECTL_USER" =~ "admin" ]] && color=red || color=blue -RPROMPT='%{$fg[$color]%}($ZSH_KUBECTL_PROMPT)%{$reset_color%}' +function right_prompt() { + local color="blue" + + if [[ "$ZSH_KUBECTL_USER" =~ "admin" ]]; then + color=red + fi + + echo "%{$fg[$color]%}($ZSH_KUBECTL_PROMPT)%{$reset_color%}" +} +RPROMPT='$(right_prompt)' ``` Also you can install with homebrew.