Add `pipx hook` command
See original GitHub issueHi! Thank you for this fabulous tool!
How would this feature be useful?
Conda offers a command conda shell.{bash|zsh|fish} hook
which can be invoked from scripts to bring the Conda environment into the current shell.
The boilerplate Conda adds to rcfiles actually invokes this command! But it’s also useful for scripts which install a sequence of tools (Conda, pipx, Poetry) to bootstrap a developer’s Python environment, with minimal interaction on their part.
I’m running pipx ensurepath
from my bootstrap script, however it doesn’t take effect until starting the next shell. Starting a new shell is a rather clunky thing to do in the middle of a shell script execution.
Describe the solution you’d like
A pipx hook {bash|zsh|fish}
command which outputs set -x PATH $PATH /Users/pnm/.local/bin
or something similar, which updates and exports PATH
in the current shell.
Another alternative (a little less nice I guess) would be a command like pipx bindir
which resolves pipx’s config and just prints /Users/pnm/.local/bin
.
Describe alternatives you’ve considered
My workaround is to hard-code ~/.local/bin in my bootstrap script. This works, however I’d have more confidence using a pipx command since I know it will honor pipx’s config. It also makes the intention of my bootstrap script more self-documenting.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (5 by maintainers)
Top GitHub Comments
That makes sense, thanks. Would you be interested in contributing such a command? I feel we can extend the idea to something like
pipx environment
,pipx constants
, or something like that (I’m not good at naming things). This would print the variables pipx uses inpipx.constants
, such asPIPX_HOME
,PIPX_SHARED_LIBS
, andPIPX_BIN_DIR
(the last is the one you’re looking for). The format can be something likeand we can maybe have an option to print a specific value like
Not sure what best to design this, other ideas are definitely welcomed.
Hi @uranusjr, I am going to implement this. 👍