Many useful prompt segments — Kubernetes context, AWS profile, Azure account, Google Cloud project — are only relevant when you are actually running a command that interacts with those services. Showing all of them unconditionally would crowd your prompt with information that is irrelevant most of the time. Powerlevel10k’s show on command feature solves this elegantly: a segment stays hidden until you start typing a command that matches a configurable pattern, at which point it appears automatically.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/romkatv/powerlevel10k/llms.txt
Use this file to discover all available pages before exploring further.
How show on command works
Each participating segment has a correspondingPOWERLEVEL9K_<SEGMENT>_SHOW_ON_COMMAND parameter. Its value is a pipe-separated (|) extended-regex pattern matched against the current command buffer. As soon as the text you are typing matches the pattern, the segment becomes visible in the prompt. When you clear the buffer or type something that no longer matches, the segment disappears again.
This happens entirely in real time as you type — no ENTER required.
Default configuration
Configs generated byp10k configure enable show on command for several segments out of the box. Here are the defaults from ~/.p10k.zsh for the most common segments:
How to customise show on command
Search for SHOW_ON_COMMAND
Use your editor’s search function to find every occurrence of
SHOW_ON_COMMAND. Each line
controls a different segment.Adjust or remove the parameter
- Show unconditionally: delete or comment out the
POWERLEVEL9K_<SEGMENT>_SHOW_ON_COMMANDline entirely. The segment will always be visible. - Change the trigger: update the pipe-separated regex to match the commands you care about.
kubectl and k9s:Toggling a segment on demand with a key binding
Sometimes you want to switch a segment between “always visible” and “visible only when relevant” without editing~/.p10k.zsh. You can define a small shell function and bind it to a key. The
following example — analogous to kubeon/kubeoff from
kube-ps1 — toggles the Kubernetes context segment.
Add this to ~/.zshrc:
Ctrl+] — by adding two more lines:
kube-toggle (by typing the function name or pressing the bound key) flips the segment
between always-on and on-command mode and immediately refreshes the prompt.
The same toggle pattern works for any segment that supports
SHOW_ON_COMMAND. Replace
KUBECONTEXT and the regex value with the appropriate segment name and command list for your
use case.