Shell Completion Scripts
Note: The completion scripts are embedded in the compiled backlog binary. These files serve as reference documentation and are used during development (the CLI reads them first if available, otherwise uses the embedded versions).
Available Shells
Zsh
File: _backlog
Installation:
-
Automatic (recommended):
backlog completion install --shell zsh -
Manual:
# Copy to a directory in your $fpath sudo cp _backlog /usr/local/share/zsh/site-functions/_backlog # Or add to your custom completions directory mkdir -p ~/.zsh/completions cp _backlog ~/.zsh/completions/_backlog # Add to ~/.zshrc if not already present: fpath=(~/.zsh/completions $fpath) autoload -Uz compinit && compinit -
Testing without installation:
# In your current zsh session fpath=(./completions $fpath) autoload -Uz compinit && compinit
Verification:
# Type and press TAB
backlog <TAB>
backlog task <TAB>
Bash
File: backlog.bash
Installation:
-
Automatic (recommended):
backlog completion install --shell bash -
Manual:
# Copy to bash-completion directory sudo cp backlog.bash /etc/bash_completion.d/backlog # Or source in ~/.bashrc echo "source /path/to/backlog.bash" >> ~/.bashrc source ~/.bashrc -
Testing without installation:
# In your current bash session source ./completions/backlog.bash
Verification:
# Type and press TAB
backlog <TAB>
backlog task <TAB>
Fish
File: backlog.fish
Installation:
-
Automatic (recommended):
backlog completion install --shell fish -
Manual:
# Copy to fish completions directory cp backlog.fish ~/.config/fish/completions/backlog.fish # Completions are automatically loaded in new fish sessions -
Testing without installation:
# In your current fish session source ./completions/backlog.fish
Verification:
# Type and press TAB
backlog <TAB>
backlog task <TAB>
How It Works
All completion scripts use the same backend:
- The shell calls the completion function when TAB is pressed
- The completion function invokes
backlog completion __complete "$BUFFER" "$CURSOR" - The CLI returns a newline-separated list of completions
- The shell presents these completions to the user
This architecture provides:
- Dynamic completions: Task IDs, labels, statuses are read from actual data
- Consistent behavior: All shells use the same completion logic
- Easy maintenance: Update completion logic once in TypeScript
- Embedded scripts: Scripts are built into the binary, no external files needed
Development
Testing Completions
Zsh:
# Run automated tests
zsh _backlog.test.zsh
# Or manually verify
zsh
source _backlog
which _backlog
Bash:
# Manually verify
bash
source backlog.bash
complete -p backlog
Fish:
# Run automated tests
fish backlog.test.fish
# Or manually verify
fish
source backlog.fish
complete -C'backlog '
Adding New Completions
Completions are generated by:
/src/completions/helper.ts- Main completion logic/src/completions/command-structure.ts- Command parsing/src/completions/data-providers.ts- Dynamic data (task IDs, labels, etc.)/src/commands/completion.ts- Embedded shell scripts ingetEmbeddedCompletionScript()
To update completion scripts:
- Edit the embedded scripts in
/src/commands/completion.ts - (Optional) Update the reference files in
/completions/for documentation - Rebuild:
bun run build
Requirements
- Zsh: Version 5.x or higher
- Bash: Version 4.x or higher
- Fish: Version 3.x or higher
Troubleshooting
Completions not working
-
Verify the CLI is in your PATH:
which backlog -
Check completion function is loaded:
# Zsh which _backlog # Bash complete -p backlog # Fish complete -C'backlog ' -
Test the completion backend directly:
backlog completion __complete "backlog task " 13This should output available subcommands for
backlog task. -
Reload your shell configuration:
# Zsh exec zsh # Bash exec bash # Fish exec fish
Slow completions
If completions feel slow, it may be because:
- Large number of tasks/documents in your backlog
- Network latency (if applicable)
- First completion triggers CLI initialization
The completion system is designed to be fast, but with very large datasets you may notice a slight delay.
Contributing
When adding new completion features:
- Update the backend in
/src/completions/ - Test with
backlog completion __complete - Verify each shell script still works
- Update this README if behavior changes