Skip to main content

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.

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.

How show on command works

Each participating segment has a corresponding POWERLEVEL9K_<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 by p10k configure enable show on command for several segments out of the box. Here are the defaults from ~/.p10k.zsh for the most common segments:
# Show kubecontext only when the command you are typing invokes one of these tools.
# Tip: Remove the next line to always show kubecontext.
typeset -g POWERLEVEL9K_KUBECONTEXT_SHOW_ON_COMMAND='kubectl|helm|kubens|kubectx|oc|istioctl|kogito|k9s|helmfile|flux|fluxctl|stern|kubeseal|skaffold|kubent|kubecolor|cmctl|sparkctl'

How to customise show on command

1

Open ~/.p10k.zsh

${EDITOR:-nano} ~/.p10k.zsh
2

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.
3

Adjust or remove the parameter

  • Show unconditionally: delete or comment out the POWERLEVEL9K_<SEGMENT>_SHOW_ON_COMMAND line entirely. The segment will always be visible.
  • Change the trigger: update the pipe-separated regex to match the commands you care about.
For example, to show the Kubernetes context only for kubectl and k9s:
typeset -g POWERLEVEL9K_KUBECONTEXT_SHOW_ON_COMMAND='kubectl|k9s'
4

Reload the configuration

exec zsh

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:
function kube-toggle() {
  if (( ${+POWERLEVEL9K_KUBECONTEXT_SHOW_ON_COMMAND} )); then
    unset POWERLEVEL9K_KUBECONTEXT_SHOW_ON_COMMAND
  else
    POWERLEVEL9K_KUBECONTEXT_SHOW_ON_COMMAND='kubectl|helm|kubens'
  fi
  p10k reload
  if zle; then
    zle push-input
    zle accept-line
  fi
}
Then bind it to a key — here Ctrl+] — by adding two more lines:
zle -N kube-toggle
bindkey '^]' kube-toggle  # ctrl-] to toggle kubecontext in powerlevel10k prompt
Invoking 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.

Build docs developers (and LLMs) love