Auto-Completion#
Dirvana aliases can inherit auto-completion from existing commands.
Basic Completion#
Use the completion field to inherit completion from another command:
aliases:
k:
command: kubecolor
completion: kubectl # Inherits kubectl completion
kust: kustomize # Native Inherits kustomize completion
kubectl: # Too lazy to set up completion for the kubectl command?
command: kubectl # No problem — just declare the command as is, and Dirvana will take care of the rest!
tf:
command: task terraform -- # Use terraform with task as wrapper
completion: terraform # And benefit from terraform completionNow when you type:
k get <TAB>
# Shows: pods, services, deployments, ...How It Works#
When you set completion: kubectl, Dirvana:
- Detects your shell (Bash or Zsh)
- Finds the completion function for
kubectl - Registers the same completion for your alias
k
Supported Commands#
Auto-completion works for commands with built-in completion support (Cobra CLI, urfave/cli, etc.) or those in the Dirvana completion registry.:
- kubectl - Kubernetes resources
- git - Branches, files, remotes
- terraform - Workspaces, resources
- docker - Containers, images
- helm - Charts, releases
- And many more!
Completion Registry#
Some commands don’t have built-in completion support. Dirvana provides a completion registry with custom completions.
Using Registry Completions#
The registry is automatically used when you specify a completion field:
aliases:
gov: govc # Uses govc completion from registryContributing to Registry#
You can contribute custom completions to the registry. See the registry README for details.
Completion for Custom Commands#
If your command doesn’t have completion support and isn’t in the registry, contribute !
Add a completion script to the Dirvana registry. See registry/README.md.
Examples#
Kubernetes Aliases#
aliases:
k:
command: kubecolor
completion: kubectl
kubectl: kubectl
kust: kustomize
kns: kubens
kctx: kubectx
h:
command: helm
completion: helmGit Aliases#
aliases:
g:
command: git
completion: git
gco:
command: git checkout
completion: git
gp:
command: git push
completion: gitDocker Aliases#
aliases:
d:
command: docker
completion: docker
dc:
command: docker compose
completion: dockerTroubleshooting#
Completion Not Working#
Check dirvana status:
dirvana status # Installs completionEnsure dirvana is setup :
dirvana setup # Reload your shell or source ~/.bashrc / ~/.zshrcIs your dirvana allowed ?
dirvana allowTest dirvana completion:
dirvana completion <command>
Completion for Wrapper Commands#
If you’re wrapping a command, use the wrapped command for completion:
aliases:
# Wrapper around kubectl
k:
command: kubecolor # Colorized kubectl
completion: kubectl # Use kubectl completionSee the completion registry for available custom completions.