Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support shell completion with pipx.pyz #1072

Closed
TomiBelan opened this issue Oct 3, 2023 · 5 comments · Fixed by #1224
Closed

Support shell completion with pipx.pyz #1072

TomiBelan opened this issue Oct 3, 2023 · 5 comments · Fixed by #1224
Labels
docs enhancement New feature or request help wanted Extra attention is needed zipapp

Comments

@TomiBelan
Copy link
Contributor

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 the register-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 as python3 /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 of

eval "$(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 second pipx is an argument to register-python-complete (telling it what to generate completions for). The 2>/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.

@dukecat0 dukecat0 added docs enhancement New feature or request labels Oct 4, 2023
@gaborbernat
Copy link
Contributor

PR to document this in the FAQ is welcome.

@gaborbernat gaborbernat added the help wanted Extra attention is needed label Dec 2, 2023
@TomiBelan
Copy link
Contributor Author

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. ❤️

@gaborbernat
Copy link
Contributor

Could be under https://pipx.pypa.io/stable/troubleshooting/

@TomiBelan
Copy link
Contributor Author

Good idea -- preferably in addition to improving the output of pipx completions.

@1trapbox
Copy link

1trapbox commented Jan 4, 2024

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 the register-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 as python3 /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 of

eval "$(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 second pipx is an argument to register-python-complete (telling it what to generate completions for). The 2>/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)"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs enhancement New feature or request help wanted Extra attention is needed zipapp
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants