Shell Completion
Overview
PyBritive supports tab completion for commands and flags in bash, zsh, fish, and PowerShell. You can also enable profile name completion so you can tab-complete profile names directly in checkout and checkin commands.
What you’ll learn:
- How to set up tab completion for your shell
- How to enable profile name completion
- How to keep the profile cache up to date automatically
Before You Begin
- PyBritive installed and authenticated — see Getting Started
- Access to your shell profile file (
~/.bashrc,~/.zshrc,~/.config/fish/, or your PowerShell profile)
Set Up Shell Completion
Generate the completion script for your shell.
bash
Generate the completion script and save it to your home directory:
_PYBRITIVE_COMPLETE=bash_source pybritive > ~/.pybritive-complete.bashAdd the following line to your ~/.bashrc:
source ~/.pybritive-complete.bashReload your shell to activate:
source ~/.bashrczsh
Generate the completion script and save it to your home directory:
_PYBRITIVE_COMPLETE=zsh_source pybritive > ~/.pybritive-complete.zshAdd the following two lines to your ~/.zshrc. The compinit line must come first — without it you will see a compdef: command not found error:
autoload -Uz compinit && compinit
source ~/.pybritive-complete.zshReload your shell to activate:
source ~/.zshrcfish
Save the completion script directly to the fish completions directory:
_PYBRITIVE_COMPLETE=fish_source pybritive > ~/.config/fish/completions/pybritive.fishNo additional configuration is needed — fish loads completions from this directory automatically. Open a new terminal to activate.
PowerShell
Find your PowerShell profile path:
echo $profileOpen that file and append the following block:
$pybritive_completion = {
param($wordToComplete, $commandAst, $cursorPosition)
$line = "$commandAst"
if ($cursorPosition -gt $line.Length) {
$line = "$line "
}
New-Item -Path Env: -Name COMP_LINE -Value $line | Out-Null
New-Item -Path Env: -Name _PYBRITIVE_COMPLETE -Value "powershell_complete" | Out-Null
Invoke-Expression pybritive -ErrorAction SilentlyContinue | Tee-Object -Var completionResult | Out-Null
Remove-Item Env:\COMP_LINE | Out-Null
Remove-Item Env:\_PYBRITIVE_COMPLETE | Out-Null
$items = $completionResult -split '\r?\n'
$items | ForEach-Object {"$_ "}
}
Register-ArgumentCompleter -Native -CommandName pybritive -ScriptBlock $pybritive_completionRestart PowerShell to activate.
Enable profile name completion
By default, completion covers commands and flags only. To also tab-complete profile names in checkout and checkin commands, cache your available profiles:
pybritive cache profilesIf you have access to multiple tenants, run this command once for each tenant.
Test it by typing pybritive checkout and pressing Tab — your available profiles should appear.
Keep the profile cache up to date
When your assigned profiles change, refresh the cache manually:
pybritive cache profilesTo have PyBritive refresh the cache automatically:
pybritive configure update global auto_refresh_profile_cache trueTo disable auto-refresh and clear the cache:
pybritive configure update global auto_refresh_profile_cache false
pybritive cache clearTroubleshoot
| Symptom | Cause | Fix |
|---|---|---|
| Tab completion not working after setup | Shell profile not reloaded | Run source ~/.zshrc (or equivalent) or open a new terminal |
compdef: command not found on zsh | compinit not initialized before sourcing completion script | Add autoload -Uz compinit && compinit before the source line in ~/.zshrc |
| Profile names not completing | Profile cache not populated | Run pybritive cache profiles |
| Profile cache is stale | New profiles assigned since last cache | Run pybritive cache profiles to refresh |
| PowerShell completion not working | Profile file not saved correctly | Confirm the block was added to the file returned by echo $profile |
Next Steps
You have completed the PyBritive CLI tutorial series. Here is a summary of what was covered:
- Getting Started — install, configure, and authenticate
- Listing Your Access — discover available profiles, applications, and secrets
- Secrets — view and download secrets from the Britive vault
- Check Out and Check In — request and return temporary credentials
- AWS Credentials — env, integrate, credential_process, and console modes
- Azure Credentials — azlogin and azps modes
- GCP Credentials — gcloudauth and gcloudauthexec modes
- OTP and Step-Up Authentication — pass a one-time password for protected profiles and secrets
- Approval Workflows — submit, approve, reject, and withdraw requests
- SSH Access — connect to private AWS and GCP instances
- Shell Completion — tab completion setup