Repository navigation
feat(nodeenv): print shell completion scripts with shtab - #460
Merged
Merged
Conversation
--print-completion SHELL prints a completion script for bash, zsh, fish or PowerShell, made by shtab from the same parser that reads the command line. shtab is an optional dependency, installed with the completion extra, and only this flag imports it: without shtab the flag stays in --help and exits with the pip command to run. Out of the box shtab leaves fish and zsh with no candidates after the options that take a path, which is worse than no script at all, so the flag marks the file and directory options. It also suggests latest, lts and system for --node and latest for --npm. The script always completes nodeenv, also when python -m nodeenv prints it. Fixes #351
The activate-shells job already installs zsh and fish, and the ubuntu image ships bash and pwsh, so it runs tests/test_completion.py with NODEENV_REQUIRE_SHELLS=1: a missing shell fails the job instead of skipping its tests.
pwsh refused the script: shtab keys its PowerShell tables by option string, PowerShell hash keys ignore case, and -c (--clean-src) clashed with -C (--config-file). The PowerShell script now leaves out -c; --clean-src and -C still complete. The other shells get the same script as before.
shtab's PowerShell script had a second bug after the -c workaround: the completer switches to an option it meets and only goes back to the positional arguments once the option has taken its values, which a flag without a value never does. DEST_DIR was not completed after --force, --prebuilt and the like. --print-completion now offers bash, zsh and fish, and the -c workaround goes away with PowerShell. Without PowerShell the completion extra needs shtab 1.11, which passes tests/test_completion.py. PowerShell can come back once shtab fixes both bugs (tqdm/shtab#267 for the first one).
This was referenced Oct 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
See CONTRIBUTING.md for the rules behind this checklist.
#351 asks for shell completion, using shtab. shtab builds the script from
the argparse parser, but out of the box it leaves fish and zsh with no
candidates after
-r,-C,-pand DEST_DIR, which is worse than havingno script: without one, both shells offer file names there.
nodeenv --print-completion SHELLprints a script forbash,zshorfishand exits:completionextra(
pip install "nodeenv[completion]",shtab>=1.11), likecertifi.Only this flag imports it, so nothing else in nodeenv needs it.
--help. Without shtab it exits with the pipcommand to run; with a shtab too old for the shell, with the same
command and
-U. No traceback in either case.-r,--local-requirements,-Cand--make, directory names after-pand for DEST_DIR.--nodeofferslatest,ltsandsystem(nosystemon Windows),--npmofferslatest.nodeenv, also whenpython nodeenv.pyorpython -m nodeenvprints it.has no Unix-only options.
PowerShell is left out for now. shtab's PowerShell script has two bugs
that showed up in CI here:
-cand-Cclash in its case-insensitivehash literals (tqdm/shtab#267), and DEST_DIR is not completed after a
flag without a value, such as
--force(tqdm/shtab#268). It can be added once shtabfixes both.
tests/test_completion.pyloads the printed script into bash, zsh andfish and checks the candidates each shell offers for the same command
lines. The
activate-shellsjob runs it withNODEENV_REQUIRE_SHELLS=1,and the tox matrix runs it wherever the shells exist. The tests also pass
with shtab 1.11.0, the minimum in the extra.
README gets a "Shell completion" section with the install command for
each shell. In zsh the script registers from
fpathor throughevalafter
compinit, but not when sourced.Fixes #351
toxpasses: the tests and flake8CHANGEShas an entry underVersion [unreleased], if nodeenv'sbehavior changes
README.rstis updated, if the change affects what it documentstype(scope): subject