Skip to content

Shell Completion

Chainsaw provides shell completion support for Bash, Zsh, Fish, and PowerShell. Once set up, you can use the key to auto-complete chainsaw commands, flags, and even some arguments, which significantly improves the command-line experience.

Generating Completion Scripts

You can generate shell completion scripts using the chainsaw completion command:

# For Bash
chainsaw completion bash

# For Zsh
chainsaw completion zsh

# For Fish
chainsaw completion fish

# For PowerShell
chainsaw completion powershell

Setting Up Completion

Bash

To enable completion in your current Bash session:

source <(chainsaw completion bash)

To enable completion for all sessions, add the above line to your ~/.bashrc file:

echo 'source <(chainsaw completion bash)' >> ~/.bashrc

Alternatively, you can save the completion script to the bash-completion directory:

# On Linux
chainsaw completion bash > /etc/bash_completion.d/chainsaw

# On macOS with Homebrew
chainsaw completion bash > $(brew --prefix)/etc/bash_completion.d/chainsaw

Zsh

To enable completion in your current Zsh session:

source <(chainsaw completion zsh)

To enable completion for all sessions, add the above line to your ~/.zshrc file:

echo 'source <(chainsaw completion zsh)' >> ~/.zshrc

Alternatively, you can save the completion script to a directory in your $fpath:

# Create a directory for completions if it doesn't exist
mkdir -p ~/.zsh/completion
# Generate and save the completion script
chainsaw completion zsh > ~/.zsh/completion/_chainsaw

# Make sure the directory is in your fpath by adding to ~/.zshrc:
echo 'fpath=(~/.zsh/completion $fpath)' >> ~/.zshrc
echo 'autoload -U compinit; compinit' >> ~/.zshrc

Fish

To enable completion in Fish:

chainsaw completion fish > ~/.config/fish/completions/chainsaw.fish

PowerShell

To enable completion in PowerShell:

chainsaw completion powershell | Out-String | Invoke-Expression

To make it persistent, add the above line to your PowerShell profile:

# Find the profile path
echo $PROFILE

# Add the completion command to your profile
chainsaw completion powershell | Out-String | Out-File -Append $PROFILE

Testing Completion

After setting up completion, you can test it by typing chainsaw followed by a space and pressing . This should show available subcommands. You can also try typing partial commands like chainsaw te and then pressing , which should complete to chainsaw test.

Detailed Reference

For more detailed information about each completion command, see the reference documentation: