@@ -20,6 +20,24 @@ Or to install the latest master (warning, maybe broken!)::
python3 -m pip install git+https://git.kernel.org/pub/scm/utils/b4/b4.git@master
+Shell completion
+----------------
+b4 makes use of the python-shtab module to provide static shell completion
+files. Currently python-shtab supports bash, zsh and tcsh, where others may be
+added in the future.
+
+To install b4 with pip and shell completion use::
+
+ python3 -m pip install b4[completion]
+
+Shell completion is provided by the command ``b4 --print-completion
+{bash,zsh,tcsh}``. To enable shell completion run::
+
+ eval $(b4 --print-completion bash)
+
+To make it permanent on new shells, add that command to your ``$HOME/.bashrc``
+or ``$HOME/.zshrc``.
+
Upgrading
---------
If you previously installed from pypi::
new file mode 100644
@@ -0,0 +1 @@
+shtab>=1.7
@@ -27,6 +27,9 @@ dynamic = ["dependencies", "optional-dependencies"]
[tool.setuptools.dynamic]
dependencies = { file = ["requirements.in"] }
+[tool.setuptools.dynamic.optional-dependencies]
+completion = { file = ["misc/requirements-completion.in"] }
+
[tool.setuptools.packages.find]
where = ['src']
exclude = ['tests*']
@@ -162,6 +162,13 @@ def setup_parser() -> argparse.ArgumentParser:
value to the empty string. Using NAME and omitting
=VALUE will set the value to "true".''')
+ try:
+ import shtab
+
+ shtab.add_argument_to(parser, ["--print-completion"])
+ except ImportError:
+ pass
+
subparsers = parser.add_subparsers(help='sub-command help', dest='subcmd')
# b4 mbox
Shell completion support was added in commit 333189c by using a shell script to generate the completion files with python-shtab. This script can be run by distribution packagers to include shell completion. However this does not support the use case of installing b4 with pip from PyPi[1], because PyPi doesn't support distributing shell completion scripts. Many tools support this by having a command line flag that can generate the completion scripts. In the original version of the shell completion by Emil Velikov this was supported with `b4 --print-completion bash`, but it was decided against to avoid bringing in more dependencies[2]. This restores Emil's work, but using a Python optional-dependency. This way the base install for b4 is unchanged, but PyPi users that want shell completion can install it with `pip install b4[completion]`. [1] https://github.com/mricon/b4/issues/47 [2] https://lore.kernel.org/tools/20240305-obedient-centipede-of-finesse-a35a86@lemur/ Signed-off-by: Brandon Maier <brandon.maier@collins.com> --- README.rst | 18 ++++++++++++++++++ misc/requirements-completion.in | 1 + pyproject.toml | 3 +++ src/b4/command.py | 7 +++++++ 4 files changed, 29 insertions(+) --- base-commit: 2a6338e451a0c1e81f214f48c820c1e52d76b2f1 change-id: 20241009-pypi-completion-83f2e22ff0d9 Best regards,