Closed TomiBelan closed 8 months ago
PR to document this in the FAQ is welcome.
FAQ? What FAQ?
pipx has the pipx completions
command. The command does not edit any shell config files directly, instead it just prints instructions to enable completion. The main goal of this issue is that pipx completions
should print working instructions.
I found a working command for Bash but someone needs to test the other shells.
Personally I'm not interested in sending a PR but I encourage anyone to do so. ❤️
Could be under https://pipx.pypa.io/stable/troubleshooting/
Good idea -- preferably in addition to improving the output of pipx completions
.
How would this feature be useful?
Users of pipx.pyz don't get shell completion for pipx. The current instructions printed by
pipx completions
don't work because theregister-python-argcomplete
command is missing. This is a limitation compared to "full" installations of pipx made with pip install --user, apt, brew, etc.To be specific, I mean users who move pipx.pyz to
~/.local/bin/pipx
(or similar) and mark it executable. I think it's probably impossible to support completion for users who run it explicitly aspython3 /path/to/pipx.pyz ...
, so they are out of scope.Describe the solution you'd like
It turns out this is already possible. It just needs to be documented in
pipx completions
. Instead ofeval "$(register-python-argcomplete pipx)"
your bash config file must contain:
eval "$(SHIV_CONSOLE_SCRIPT=register-python-argcomplete pipx pipx 2>/dev/null)"
I only tested bash. Someone please test the other shells.
Explanation: SHIV_CONSOLE_SCRIPT tells the shiv bootstrap code to use another script bundled inside pipx.pyz. The first
pipx
is the program to run. The secondpipx
is an argument to register-python-complete (telling it what to generate completions for). The2>/dev/null
is necessary to work around linkedin/shiv#240, at least for now.Describe alternatives you've considered
Another option could be to stop using argcomplete and rewrite the whole pipx CLI code with click. pipx already depends on click indirectly because of userpath. click's completion support does not depend on other programs, so it works nicely with pyz files and doesn't need SHIV_CONSOLE_SCRIPT. However all existing users of completion would have to change their configs.
I don't use pipx completion and I don't personally care about this issue. I'm just filing it because I noticed it doesn't already exist.
pipx completions
Doesn't work for me (installed using asdf, other installation methods have not been tested)
This solved my problem, thanks
pipx install argcomplete
# Zsh (add to .zshrc)
eval "$(register-python-argcomplete pipx)"
How would this feature be useful?
Users of pipx.pyz don't get shell completion for pipx. The current instructions printed by
pipx completions
don't work because theregister-python-argcomplete
command is missing. This is a limitation compared to "full" installations of pipx made with pip install --user, apt, brew, etc.To be specific, I mean users who move pipx.pyz to
~/.local/bin/pipx
(or similar) and mark it executable. I think it's probably impossible to support completion for users who run it explicitly aspython3 /path/to/pipx.pyz ...
, so they are out of scope.Describe the solution you'd like
It turns out this is already possible. It just needs to be documented in
pipx completions
. Instead ofyour bash config file must contain:
I only tested bash. Someone please test the other shells.
Explanation: SHIV_CONSOLE_SCRIPT tells the shiv bootstrap code to use another script bundled inside pipx.pyz. The first
pipx
is the program to run. The secondpipx
is an argument to register-python-complete (telling it what to generate completions for). The2>/dev/null
is necessary to work around linkedin/shiv#240, at least for now.Describe alternatives you've considered
Another option could be to stop using argcomplete and rewrite the whole pipx CLI code with click. pipx already depends on click indirectly because of userpath. click's completion support does not depend on other programs, so it works nicely with pyz files and doesn't need SHIV_CONSOLE_SCRIPT. However all existing users of completion would have to change their configs.
I don't use pipx completion and I don't personally care about this issue. I'm just filing it because I noticed it doesn't already exist.