Closed pietrinoatzenimfm closed 3 years ago
Try this:
POWERLEVEL9K_KUBECONTEXT_SHOW_ON_COMMAND
.function p10k-on-post-widget() {
local z=$'\0'
if [[ -n $DIRENV_DIR ]] || (( P9K_COMMANDS[(I)(|*$z)kubectl] )); then
p10k display '*/kubectl'=show
else
p10k display '*/kubectl'=hide
fi
}
I tried, but nothing happens (I see the default kubecontext displayed even if I'm not in a folder that's supposed to have kubernetes code).
BTW: I see the p10k-on-post-widget function is executed if I add some echo, but I really don't understand what's doing to debug further. Do you have a guide for low level usage of p10k?
Oh, I might better specify the requirement too: what I'd like to do is to have a folder with K8s code, and a .envrc in which I specify/enable the p10k section for kubecontext (i.e. with a var like P10K_ENABLE_KUBECONTEXT). But in all other folders I'd like that to use the default SHOW_ON_COMMAND.
I tried, but nothing happens (I see the default kubecontext displayed even if I'm not in a folder that's supposed to have kubernetes code).
This is unexpected. What's the output of functions p10k-on-post-widget
?
Maybe I misunderstood what you want. Anyway, you can adjust the condition in the code as you like. (( P9K_COMMANDS[(I)(|*$z)kubectl] ))
evaluates to true if the current command invokes kubectl
. The rest is self-explanatory.
I figured it out, and I almost fixed it with this (note the change in the name of the p10k part):
function p10k-on-post-widget() {
local z=$'\0'
if [[ -n $DIRENV_DIR ]] || (( P9K_COMMANDS[(I)(|*$z)kubectl] )); then
p10k display '*/kubecontext'=show
else
p10k display '*/kubecontext'=hide
fi
}
The only strange behavior I notice is that this applies only "after" I do something in the prompt (i.e. I start writing any command). I'll try to explain better below:
How do you "move to a folder"?
I mean "cd"...
Also, what I'm noticing is that direnv loads (or unloads) its environment after I execute "cd" into a specific folder. I don't know if this might interfere with p10k-on-post-widget.
Try adding this:
function p10k-on-post-widget() {
if [[ -n $DIRENV_DIR ]]; then
p10k display '*/kubecontext'=show
else
p10k display '*/kubecontext'=hide
fi
}
Also make sure that POWERLEVEL9K_KUBECONTEXT_SHOW_ON_COMMAND
isn't set.
Same thing: changing directory doesn't update the prompt until I press any character (POWERLEVEL9K_KUBECONTEXT_SHOW_ON_COMMAND is not set).
That's unfortunate. I'm afraid I cannot spare any more time on this. Sorry.
I think this works:
function p10k-on-post-widget() {
local z=$'\0'
if [[ -v P10K_ENABLE_KUBECONTEXT ]] || (( P9K_COMMANDS[(I)(|*$z)kubectl|helm|kubens|kubectx|oc|istioctl|kogito|k9s|helmfile] )); then
p10k display '*/kubecontext'=show
else
p10k display '*/kubecontext'=hide
fi
}
just by restarting the terminal and not sourcing ~./zshrc. Thanks a lot!
just by restarting the terminal and not sourcing ~./zshrc. Thanks a lot!
https://github.com/romkatv/powerlevel10k#weird-things-happen-after-typing-source-zshrc
Hi, I was wondering if there's a simple way to disable SHOW_ON_COMMAND on specific folders only. I'd use this to enable or disable kubecontext if I'm in a folder that contains a .envrc for direnv. I found that I'm able to unset the variable and reload p10k, but direnv doesn't recognize the p10k script.