A reasonably current pip comes with built-in functionality to create completion helpers for bash, zsh or fish:
$ pip help completion
Usage: pip completion [options]
Description:
A helper command to be used for command completion.
Completion Options:
-b, --bash Emit completion code for bash
-z, --zsh Emit completion code for zsh
-f, --fish Emit completion code for fish
You can use it like so:
pip completion --bash >> ~/.bashrc
And then start a new shell or source ~/.bashrc to have it take effect.
git clone https://github.com/ekalinin/pip-bash-completion.git
sudo cp ./pip-bash-completion/pip /etc/bash_completion.d/
. /etc/bash_completion.d/pip # to enable in the current shell, next time should load automatically
I would like to complete muru’s answer answer.
I like to keep my .bashrc relatively clean, plus if you use the following code, you won't have to update your .bashrc if/when the completion snippet has an update!
Just add this single line to your .bashrc:
eval "$(pip completion --bash)"
Also, you might want to add that line too, because the completion is only added to pip, not pip3:
complete -o default -F _pip_completion pip3
UPDATE:
Running the command each time a new terminal is open is actually slow. It takes from 1 to 5 seconds on my PC. I used muru’s answer at the end.
A reasonably current
pip
comes with built-in functionality to create completion helpers for bash, zsh or fish:You can use it like so:
And then start a new shell or
source ~/.bashrc
to have it take effect.UPDATE: Don’t forget to look at muru’s answer which may provide a more straightforward solution.
A
pip
autocompletion plugin for Bash can be found at https://github.com/ekalinin/pip-bash-completion.You can download it as a ZIP or simply install using Git:
I would like to complete muru’s answer answer. I like to keep my
.bashrc
relatively clean, plus if you use the following code, you won't have to update your.bashrc
if/when the completion snippet has an update!Just add this single line to your
.bashrc
:Also, you might want to add that line too, because the completion is only added to
pip
, notpip3
:UPDATE: Running the command each time a new terminal is open is actually slow. It takes from 1 to 5 seconds on my PC. I used muru’s answer at the end.