-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
custom color depending on context does not update within current shell #23
Comments
I figured out that this line is not updating the
Manually setting the
|
GOT ITSomeone feel free to correct my work. So, this is the important line where color is being set into the right-prompt. Whatever
And from my previous comment we know that the `$color variable is not getting re-calculated. Thats because this line is not getting re-run on every terminal command
The solutionis to put that color calculation logic into the RPROMPT. This works for me now! Like so
On a different note, I found it nicer to set the background color to red/green as opposed to the foreground. This is what I'm using
|
I'm sorry for the late reply.
zsh-kubectl-prompt creates the followting 4 variables:
So, using
This is light way because it does not run If you have more complicated conditions, I recommend to define it as a function. function right_prompt() {
local color="green"
if [[ "$ZSH_KUBECTL_CONTEXT" =~ "aks-prod" ]]; then
color="red"
fi
echo "%{$fg[$color]%}[$ZSH_KUBECTL_PROMPT]%{$reset_color%}"
}
RPROMPT='$(right_prompt)' |
I have the following in my .zshrc
I want the color of the prompt to be red if my context is the production cluster.
For starters, I was unable to use
ZSH_KUBECTL_CONTEXT
(it doesn't get set in my environment), so I'm callingkubectl config current-context
againMy problem:
Suppose I'm on my
development
context, the prompt color is green. Then I switch my context toproduction
- I expect to see the prompt color change to red. It remains green instead of changing to red.However, opening a new shell forces the prompt color to change to red.
I'm probably not doing something correct, please help.
The text was updated successfully, but these errors were encountered: