CLI Autocompletion Setup
About 822 words
Set up tab autocompletion for the TKA CLI to get command suggestions, flag completion, and faster command line workflow.
Overview
TKA includes built-in autocompletion support for all major shells. Once configured, you can use Tab to:
- Complete command names (
tka log<Tab>→tka login) - Complete subcommands (
tka get <Tab>→ showskubeconfig,login) - Complete flag names (
tka --<Tab>→ shows all available flags) - Complete flag values (theme names, shell types, etc.)
Supported Shells
- Bash (4.0+)
- Zsh
- Fish
- PowerShell
Installation
Generate Completion Script
TKA can generate completion scripts for your shell:
tka completion [bash|zsh|fish|powershell]Install Completion
bashAdd to your
~/.bashrc:# TKA completion source <(tka completion bash)zshAdd to your
~/.zshrc:# TKA completion source <(tka completion zsh) # If you get compdef errors, add this before the source line: autoload -U compinit && compinitfishFish completions are automatically loaded from the right location:
# Install completion $ tka completion fish > ~/.config/fish/completions/tka.fish # Reload Fish configuration $ source ~/.config/fish/config.fishPowerShell# Create profile directory if it doesn't exist PS> New-Item -Type Directory -Path (Split-Path $PROFILE) -Force # Add completion to your profile PS> tka completion powershell >> $PROFILE # Reload profile PS> . $PROFILE
Verification
Test that autocompletion is working:
# Type this and press Tab
$ tka <Tab>
generate completion get integration kubeconfig login reauthenticate shell signout version
# Test flag completion
$ tka --<Tab>
--config --debug --help --long --no-eval --port --server --theme --version
# Test subcommand completion
$ tka get <Tab>
kubeconfig loginTroubleshooting
Bash Completion Not Working
Solutions:
:- 1. Reload shell completely
Reload shell# Close and reopen terminal, or $ exec $SHELL:- 2. Check bash-completion package
Install bash-completion package# Ubuntu/Debian $ sudo apt install bash-completion # macOS with Homebrew $ brew install bash-completion # RHEL/CentOS $ sudo yum install bash-completion
Zsh Completion Issues
Solution: Ensure completion system is initialized:
# Add to ~/.zshrc before the completion source line
autoload -U compinit && compinitSolution: Place completion in Oh My Zsh custom directory:
mkdir -p ~/.oh-my-zsh/custom/plugins/tka
tka completion zsh > ~/.oh-my-zsh/custom/plugins/tka/_tka
# Add 'tka' to plugins in ~/.zshrc
plugins=(... tka)Fish Completion Issues
Solutions:
:- 1. Check Fish version:
fish --version # Requires Fish 3.0+:- 2. Verify completion file location:
ls ~/.config/fish/completions/tka.fish:- 3. Regenerate completions:
rm ~/.config/fish/completions/tka.fish tka completion fish > ~/.config/fish/completions/tka.fish
PowerShell Completion Issues
Solution: Check execution policy:
# Check current policy
Get-ExecutionPolicy
# If restricted, allow scripts for current user
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUserAdvanced Configuration
Custom Completion Behavior
You can customize completion behavior by modifying the generated script or using shell-specific configuration.
Bash: Case-Insensitive Completion
Add to ~/.inputrc:
# Case-insensitive completion
set completion-ignore-case on
# Show all matches immediately
set show-all-if-ambiguous on
# Color completion matches
set colored-stats onZsh: Enhanced Completion Styling
Add to ~/.zshrc:
# Better completion styling
zstyle ':completion:*' menu select
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}'
# Group completions by type
zstyle ':completion:*' group-name ''
zstyle ':completion:*:descriptions' format '%B%d%b'Fish: Custom Completion Priorities
Fish automatically handles intelligent completion ordering, but you can customize behavior in ~/.config/fish/config.fish:
# Customize completion paging
set -g fish_pager_color_completion cyan
set -g fish_pager_color_description yellow
set -g fish_pager_color_prefix blueIntegration with Shell Wrapper
If you're using shell integration, autocompletion will work seamlessly with the tka wrapper function. The completion system understands both the wrapper and the underlying tka binary.
Updating Completions
When you update TKA, you may want to regenerate completion scripts to get the latest commands and flags:
# Bash
tka completion bash > ~/.local/share/bash-completion/completions/tka
# Zsh
tka completion zsh > ~/.zsh/completions/_tka
# Fish
tka completion fish > ~/.config/fish/completions/tka.fish
# PowerShell
tka completion powershell | Out-File -FilePath $PROFILE -ForceWhat Gets Completed
TKA's autocompletion provides intelligent suggestions for:
Commands
login- Sign in and configure kubectlget- Retrieve resourcesshell- Start temporary subshellgenerate integration- Generate shell integrationcompletion- Generate completion scriptskubeconfig- Fetch kubeconfigreauthenticate- Refresh authenticationsignout- Sign out and cleanupversion- Show version information
Subcommands
get kubeconfig- Get current kubeconfigget login- Show login status
Flags
--config, -c- Configuration file--debug- Enable debug logging--help, -h- Show help--long, -l- Verbose output--no-eval, -e- Disable environment evaluation--port, -p- Server port--server, -s- Server address--theme, -t- Output theme--version, -v- Show version
Values
- Themes:
ascii,dark,dracula,tokyo-night,light,notty - Shells:
bash,zsh,fish,powershell - File paths: Intelligent file/directory completion for config files
Related Documentation
- Shell Integration Setup - Automatic environment variable updates
- CLI Reference - Complete command documentation
- Getting Started(Open in new window) - Basic TKA usage
