Skip to main content

Shell Completion

The xyz completion command generates shell completion scripts for faster command entry.

Supported Shells

ShellCommand
Bashxyz completion bash
Zshxyz completion zsh
Fishxyz completion fish
PowerShellxyz completion powershell

Installation

Temporary (Current Session)

source <(xyz completion bash)

Permanent (Add to Profile)

Add to ~/.bashrc:
echo 'source <(xyz completion bash)' >> ~/.bashrc
source ~/.bashrc

System-Wide

xyz completion bash > /etc/bash_completion.d/xyz
System-wide installation requires root/sudo access.

Usage

After installation, press Tab to complete commands:
xyz ke<Tab>      # Completes to: xyz keys
xyz keys ge<Tab> # Completes to: xyz keys generate
xyz prog<Tab>    # Completes to: xyz program

Command Completion

xyz <Tab><Tab>
# Shows all available commands:
# balance    chain      completion config     help
# init       keys       localnet   program    token      tx

Subcommand Completion

xyz program <Tab><Tab>
# Shows subcommands:
# build    deploy   execute  info     list     query

Flag Completion

xyz balance --<Tab><Tab>
# Shows flags:
# --all    --help   --key    --node   --output

Completion Features

Command Descriptions

With zsh and fish, completions include descriptions:
xyz <Tab>
balance    -- Query account balance
chain      -- Chain information commands
completion -- Generate shell completion script
config     -- Configuration management
...

Dynamic Completions

Some completions are context-aware:
xyz balance --output <Tab>
# Shows: table  json

xyz config set keyring-backend <Tab>
# Shows: os  file  test

Troubleshooting

Ensure bash-completion is installed:macOS:
brew install bash-completion
Ubuntu/Debian:
apt install bash-completion
Add to ~/.bashrc:
[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && \
  source "/usr/local/etc/profile.d/bash_completion.sh"
Enable completion system in ~/.zshrc:
autoload -U compinit && compinit
Reload:
source ~/.zshrc
Remove cached completions and regenerate:Zsh:
rm -f ~/.zcompdump*
compinit
Bash:
complete -r xyz
source <(xyz completion bash)
For system-wide installation:
sudo xyz completion bash > /etc/bash_completion.d/xyz

Verify Installation

Test that completions are working:
# Type this and press Tab
xyz ba<Tab>
# Should complete to: xyz balance

xyz keys <Tab><Tab>
# Should show: export  generate  import  list
If completions work, you’re all set. If not, check the troubleshooting section above.