Configure Shell Completion¶
pip-compile and pip-sync both support shell completion, but it needs to be
explicitly enabled.
Completions are output by special invocations of pip-compile and pip-sync.
You can either get completions by evaluating this output each time your shell
starts, or by writing the output to files and sourcing those files.
Completion Using eval¶
Add this to ~/.bashrc:
eval "$(_PIP_COMPILE_COMPLETE=bash_source pip-compile)"
eval "$(_PIP_SYNC_COMPLETE=bash_source pip-sync)"
Add this to ~/.zshrc:
eval "$(_PIP_COMPILE_COMPLETE=zsh_source pip-compile)"
eval "$(_PIP_SYNC_COMPLETE=zsh_source pip-sync)"
Add this to your PowerShell profile ($PROFILE):
$env:_PIP_COMPILE_COMPLETE = 'powershell_source'
pip-compile | Out-String | Invoke-Expression
Remove-Item Env:_PIP_COMPILE_COMPLETE
$env:_PIP_SYNC_COMPLETE = 'powershell_source'
pip-sync | Out-String | Invoke-Expression
Remove-Item Env:_PIP_SYNC_COMPLETE
Completions from Sourced Files¶
The eval-style method of completion means that pip-compile and pip-sync are
invoked each time a shell is started, which can be slow.
Simply saving the output to a file and sourcing that file can make completions
faster – this is also the primary way that fish shell completions work.
Save completions to a file somewhere:
_PIP_COMPILE_COMPLETE=bash_source pip-compile > ~/.pip-tools-complete.bash
_PIP_SYNC_COMPLETE=bash_source pip-sync >> ~/.pip-tools-complete.bash
Add this to ~/.bashrc:
. ~/.pip-tools-complete.bash
Save completions to a file somewhere:
_PIP_COMPILE_COMPLETE=zsh_source pip-compile > ~/.pip-tools-complete.zsh
_PIP_SYNC_COMPLETE=zsh_source pip-sync >> ~/.pip-tools-complete.zsh
Add this to ~/.zshrc:
. ~/.pip-tools-complete.zsh
Save completions into ~/.config/fish/completions/:
_PIP_COMPILE_COMPLETE=fish_source pip-compile > ~/.config/fish/completions/pip-tools.fish
_PIP_SYNC_COMPLETE=fish_source pip-sync >> ~/.config/fish/completions/pip-tools.fish
Save completions to a file somewhere:
$env:_PIP_COMPILE_COMPLETE = 'powershell_source'
pip-compile | Out-File -Encoding utf8 ~/.pip-tools-complete.ps1
Remove-Item Env:_PIP_COMPILE_COMPLETE
$env:_PIP_SYNC_COMPLETE = 'powershell_source'
pip-sync | Out-File -Append -Encoding utf8 ~/.pip-tools-complete.ps1
Remove-Item Env:_PIP_SYNC_COMPLETE
Add this to your PowerShell profile ($PROFILE):
. ~/.pip-tools-complete.ps1