Skip to content
Shell completion

Shell completion

kx completion <bash|zsh|fish|powershell>

prints a completion script for that shell. What makes it worth installing is what it completes: not just command names and flags, but the indexes from your saved listing, each labeled with the resource it points at.

$ kx describe <TAB>
1  api-7d8f-p4k2 (Pod)
2  billing-5c4b-x9m1 (Pod)
3  cache-9a1e-t7w3 (Pod)

Which is the difference between remembering a number and reading one.

What completes

PositionCandidates
The first wordCommands, plus every kind the shorthand accepts
<index>Indexes from the current listing, with names and kinds, plus every mark as @name
<index> for kx ns / kx contextThe namespace and context slots, not the history stack
<position> for kx stateHistory positions
<action> for kx rolloutstatus, restart, pause, resume, history, undo
<name> for kx theme / kx engineThe palettes and scan engines
-nNamespace names
--sortColumn names: kx’s own for kx diag, kx scan and kx events, and for a listing the columns kx last printed for that kind, so kx get pods once and kx get pods --sort re<TAB> offers ready and restarts
<src> / <dest> for kx cpLocal paths, from the shell’s own file completion

All of it is answered from ~/.kx/state.json and registries compiled into the binary. Nothing shells out to kubectl or calls the API server, because a completion that waits on a cluster is a completion people turn off.

Installing it

zsh

kx completion zsh > "${fpath[1]}/_kx"

Then start a new shell. If completion isn’t initialized yet, add autoload -Uz compinit && compinit to ~/.zshrc first.

bash

source <(kx completion bash)

To make it permanent, write it somewhere bash-completion reads:

kx completion bash > /etc/bash_completion.d/kx          # system-wide
kx completion bash > ~/.local/share/bash-completion/completions/kx

fish

kx completion fish > ~/.config/fish/completions/kx.fish

PowerShell

kx completion powershell | Out-String | Invoke-Expression

Append that to your profile to keep it.

Installed as a krew plugin, the command is kubectl idx, and kubectl completes it by running kubectl_complete-idx — the link the install page adds beside the plugin. That covers kubectl idx <TAB> in every shell, and the alias kx="kubectl idx" in zsh, which completes an alias as what it stands for and so never consults a _kx script. In bash, the script above completes the alias as well.