Skip to content
Shell Completion

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.bash

Add the following line to your ~/.bashrc:

source ~/.pybritive-complete.bash

Reload your shell to activate:

source ~/.bashrc

zsh

Generate the completion script and save it to your home directory:

_PYBRITIVE_COMPLETE=zsh_source pybritive > ~/.pybritive-complete.zsh

Add 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.zsh

Reload your shell to activate:

source ~/.zshrc

fish

Save the completion script directly to the fish completions directory:

_PYBRITIVE_COMPLETE=fish_source pybritive > ~/.config/fish/completions/pybritive.fish

No additional configuration is needed — fish loads completions from this directory automatically. Open a new terminal to activate.

PowerShell

Find your PowerShell profile path:

echo $profile

Open 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_completion

Restart 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 profiles

If 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 profiles

To have PyBritive refresh the cache automatically:

pybritive configure update global auto_refresh_profile_cache true

To disable auto-refresh and clear the cache:

pybritive configure update global auto_refresh_profile_cache false
pybritive cache clear

Troubleshoot

SymptomCauseFix
Tab completion not working after setupShell profile not reloadedRun source ~/.zshrc (or equivalent) or open a new terminal
compdef: command not found on zshcompinit not initialized before sourcing completion scriptAdd autoload -Uz compinit && compinit before the source line in ~/.zshrc
Profile names not completingProfile cache not populatedRun pybritive cache profiles
Profile cache is staleNew profiles assigned since last cacheRun pybritive cache profiles to refresh
PowerShell completion not workingProfile file not saved correctlyConfirm 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:

Last updated on