Shell completion
Prysm's beacon-chain and validator CLIs support shell completion for Bash, Zsh, and Fish shells. Once enabled, you can press TAB to auto-complete subcommands, nested commands, and flags, significantly improving your command-line experience.
Generating completion scripts
Each binary includes a completion subcommand that generates shell-specific completion scripts.
- Bash
- Zsh
- Fish
# Generate the completion script
beacon-chain completion bash
# Or for the validator
validator completion bash
# Generate the completion script
beacon-chain completion zsh
# Or for the validator
validator completion zsh
# Generate the completion script
beacon-chain completion fish
# Or for the validator
validator completion fish
Loading completions
Temporary (current session only)
Load completions for the current terminal session:
- Bash
- Zsh
- Fish
# Load beacon-chain completions
source <(beacon-chain completion bash)
# Load validator completions
source <(validator completion bash)
# Load beacon-chain completions
source <(beacon-chain completion zsh)
# Load validator completions
source <(validator completion zsh)
# Load beacon-chain completions
beacon-chain completion fish | source
# Load validator completions
validator completion fish | source
Persistent (all future sessions)
To enable completions automatically in all new terminal sessions, save the completion scripts to the appropriate location for your shell:
- Bash
- Zsh
- Fish
# User-local installation (recommended)
mkdir -p ~/.local/share/bash-completion/completions
beacon-chain completion bash > ~/.local/share/bash-completion/completions/beacon-chain
validator completion bash > ~/.local/share/bash-completion/completions/validator
The user-local directory requires bash-completion 2.0 or later. On older systems, you may need to install completions to the system-wide /etc/bash_completion.d/ directory as root.
# Create a user-local completions directory and add to fpath
mkdir -p ~/.zsh/completion
beacon-chain completion zsh > ~/.zsh/completion/_beacon-chain
validator completion zsh > ~/.zsh/completion/_validator
If you haven't already, add the completions directory to your fpath in ~/.zshrc:
echo 'fpath=(~/.zsh/completion $fpath)' >> ~/.zshrc
echo 'autoload -Uz compinit && compinit' >> ~/.zshrc
You may need to start a new shell or run compinit for completions to take effect.
# Save to Fish completions directory
beacon-chain completion fish > ~/.config/fish/completions/beacon-chain.fish
validator completion fish > ~/.config/fish/completions/validator.fish
Using completions
Once completions are loaded, press TAB to see available options:
Command completion
# Type partial command and press TAB
beacon-chain db<TAB>
# Completes to: beacon-chain db
beacon-chain db <TAB>
# Shows: restore ...
Flag completion
# Type -- and press TAB to see all flags
beacon-chain --<TAB>
# Shows: --datadir --execution-endpoint --checkpoint-sync-url ...
# Type partial flag name and press TAB
beacon-chain --exec<TAB>
# Shows: --execution-endpoint --execution-headers
Contextual completion
Completions are context-aware. The available suggestions change based on the subcommand you're using:
# Global beacon-chain flags
beacon-chain --<TAB>
# Subcommand-specific flags
beacon-chain db restore --<TAB>
Using with prysm.sh
If you run Prysm using the prysm.sh script, you can still use completion by first building or downloading the binaries. The completion scripts work with the standalone beacon-chain and validator binaries.
# Example: If using downloaded binaries
./beacon-chain completion bash > ~/.local/share/bash-completion/completions/beacon-chain
How it works
The shell completion scripts use urfave/cli's built-in completion mechanism. When you press TAB, the shell runs the binary with a hidden --generate-bash-completion flag appended to your current input. The binary returns a list of valid completions for your context, which the shell then presents as suggestions.
This means completions always reflect the current binary's actual flags and commands - they're never out of date.
Troubleshooting
Completions not working after installation
Start a new terminal session - Completion scripts are typically loaded when the shell starts
Check the script location - Ensure the completion script is in the correct directory for your shell
Verify bash-completion is installed (Bash only):
# Debian/Ubuntu
apt install bash-completion
# macOS with Homebrew
brew install bash-completion@2
Zsh completions not loading
Ensure compinit is called in your ~/.zshrc:
autoload -Uz compinit && compinit
If completions still don't work, try rebuilding the completion cache:
rm -f ~/.zcompdump && compinit
Permission denied errors
If you get permission errors when installing to system directories, use the user-local installation method instead (see persistent installation above). User-local completions work identically and don't require elevated privileges.