Shell Completion
argsh can generate shell completion scripts for bash, zsh, and fish. Completions are derived automatically from your :usage and :args declarations — subcommands, flags, and their descriptions are all included.
How It Works
Every script built with :usage gets a built-in completion subcommand for free. No extra code required:
The completion command is an Additional Command — it's always available even though it doesn't appear in your usage array. argsh detects it as a special command and generates the appropriate completion script.
Prerequisites
Your script must use :usage for subcommand dispatch:
With this declaration, ./myapp completion bash produces a completion script that knows about serve, build, deploy, --verbose, --config, and --help.
Generating Completions
Bash
Add to your ~/.bashrc or ~/.bash_profile:
Or save to the system completions directory:
For the best experience, install the bash-completion package:
Zsh
Add to your ~/.zshrc:
Or save to your fpath:
If you're using Oh My Zsh, place the file in ~/.oh-my-zsh/completions/:
Fish
Save to the Fish completions directory:
What Gets Completed
The generated scripts include:
| Source | Completed |
|---|---|
usage array entries | Subcommand names |
args array flags | --long and -s short flags |
help|h:+ (auto-added) | --help / -h |
Hidden commands (prefixed with # in the usage array) and group separators (-) are excluded from completions.
Example Output
For the example script above, ./myapp completion bash produces:
CI/CD Integration
Generate and publish completion scripts as part of your release:
# .github/workflows/release.yml
steps:
- name: Generate completions
run: |
./myapp completion bash > completions/myapp.bash
./myapp completion zsh > completions/_myapp
./myapp completion fish > completions/myapp.fish
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: completions
path: completions/
Help
Run completion --help to see available shells: