Pip has a long list of commands. Is there any way to use auto-complete by Tab in console (Bash)?

  • nice! i it work for me like charm – Yurij Apr 19 '18 at 15:06
  • @Melebius that counts as an answer. Please answer, ping me and I'll come back to upvote! – Fabby Apr 19 '18 at 15:11
  • yes, this comment is a right answer for me. – Yurij Apr 19 '18 at 15:54

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:

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
| improve this answer | |

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]

  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.

| improve this answer | |
  • For the moment the problem is solved with help of @Melebius. I would try your solution too, thanks. – Yurij Apr 20 '18 at 15:58
  • Funny that the completion does not install automatically together with pip if the code is contained in it… – Melebius Apr 21 '18 at 7:18
  • @Melebius there's no good way for it to do so - packages can't touch files in the user home directories, and installing globally to /etc/bash.bashrc is tricky to do automatically – muru Apr 21 '18 at 11:08
  • 1
    @muru As you can see in my answer and the linked page, there is also the directory /etc/bash_completion.d/ where it could be placed more easily. – Melebius Apr 21 '18 at 15:37
  • 1
    @Melebius which is from the bash-completion package, and those are two rather independent packages. This built-in completion code doesn't depend at all on bash-completion, so why would it use that directory? – muru Apr 21 '18 at 15:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.