Ahh CLI provides shell completion support for bash, zsh, and fish, making it easier to discover and use commands.
How Completions Work
Ahh CLI uses the AHH_COMPLETIONS environment variable to generate shell completion scripts. When this variable is set to 1, the CLI outputs a completion script instead of running normal commands.
if ( process . env . AHH_COMPLETIONS ) {
main . showCompletionScript ();
process . exit ( 0 );
}
This mechanism is automatically used during installation to generate the completion script at ~/.ahh/_ahh.
Automatic Setup
Shell completions are automatically configured when you install Ahh CLI using the official installation script.
During installation, the script:
Generates the completion script:
AHH_COMPLETIONS = 1 ~/.ahh/bin/ahh > ~/.ahh/_ahh
Adds completion sourcing to your shell configuration file
Detects your shell (bash, zsh, or fish) and configures accordingly
Manual Setup
If you need to set up completions manually or reinstall them:
Generate completion script
Create the completion script file: AHH_COMPLETIONS = 1 ahh > ~/.ahh/_ahh
Add to shell configuration
Add the completion script to your shell’s configuration file based on your shell: Add to ~/.bashrc: # ahh completions
[ -s " $HOME /.ahh/_ahh" ] && source " $HOME /.ahh/_ahh"
Then reload: Add to ~/.zshrc: # ahh completions
[ -s " $HOME /.ahh/_ahh" ] && source " $HOME /.ahh/_ahh"
Then reload: Add to ~/.config/fish/config.fish: # ahh completions
[ -s " $HOME /.ahh/_ahh" ] && source " $HOME /.ahh/_ahh"
Then reload: source ~/.config/fish/config.fish
Installation Script Example
The official installation script automatically configures completions for your shell. Here’s how it works:
# Generate completion script
AHH_COMPLETIONS = 1 " $exe " > " $install_dir /_ahh"
# Detect shell type
shell_type = $( basename " $SHELL " )
case " $shell_type " in
fish )
shell_config = " $HOME /.config/fish/config.fish"
;;
zsh )
shell_config = " $HOME /.zshrc"
;;
bash )
shell_config = " $HOME /.bashrc"
;;
esac
# Add completion sourcing to shell config
echo -e "# ahh completions" >> " $shell_config "
echo -e "[ -s \" $install_dir /_ahh \" ] && source \" $install_dir /_ahh \" " >> " $shell_config "
The script checks if completions are already configured to avoid duplicate entries in your shell configuration.
Using Completions
Once configured, you can use tab completion to:
Complete Commands
Press Tab after typing ahh to see available commands:
ahh [Tab]
# Shows: clip, qr, serve, share-discord, tunnel, update, webhook, workspace
Complete Options
Press Tab after typing a command to see its options:
ahh tunnel --[Tab]
# Shows: --port, -p, --help
Complete Arguments
For commands with predefined choices, tab completion shows available values:
ahh workspace [Tab]
# Shows available workspace templates
Verifying Completions
Check completion file exists
The file should exist and contain shell completion code.
Check shell configuration
Verify the completion is sourced in your shell config: # For bash
grep "ahh completions" ~/.bashrc
# For zsh
grep "ahh completions" ~/.zshrc
# For fish
grep "ahh completions" ~/.config/fish/config.fish
Test completion
Open a new terminal and try tab completion: You should see a list of available commands.
Troubleshooting
Solutions:
Verify the completion file exists:
Check if it’s sourced in your shell config:
cat ~/.zshrc | grep ahh # or ~/.bashrc for bash
Reload your shell configuration:
source ~/.zshrc # or source ~/.bashrc for bash
Regenerate the completion script:
AHH_COMPLETIONS = 1 ahh > ~/.ahh/_ahh
Completions show old commands
If completions show outdated commands after an update, regenerate the completion script: # Regenerate completions
AHH_COMPLETIONS = 1 ahh > ~/.ahh/_ahh
# Reload shell
source ~/.zshrc # or appropriate config file
The installation script supports bash, zsh, and fish. For other shells:
Generate the completion script:
AHH_COMPLETIONS = 1 ahh > ~/.ahh/_ahh
Manually add sourcing to your shell’s configuration file:
[ -s " $HOME /.ahh/_ahh" ] && source " $HOME /.ahh/_ahh"
The completion script uses bash-compatible syntax, so it may work with other bash-compatible shells.
Updating Completions
When you update Ahh CLI, you should regenerate the completion script to ensure it includes any new commands or options:
# Update CLI
ahh update
# Regenerate completions
AHH_COMPLETIONS = 1 ahh > ~/.ahh/_ahh
# Reload shell
source ~/.zshrc # or appropriate config file
Always regenerate completions after updating the CLI to ensure they match the current version’s commands and options.