Linux maintainer tooling and workflows
 help / color / mirror / Atom feed
* [PATCH b4] Support python argcomplete
@ 2026-08-07 23:17 Jason Gunthorpe
  2026-08-11 23:28 ` Konstantin Ryabitsev
  0 siblings, 1 reply; 3+ messages in thread
From: Jason Gunthorpe @ 2026-08-07 23:17 UTC (permalink / raw)
  To: tools

argcomplete is a alternative to shtab. While shtab provides an option to
generate unique matching patterns for each program, argcomplete has a
general completion hook that identifies compatible programs and
dynamically pulls the completion out of the program itself.

This means that once argcomplete is enabled in the shell every compatible
program automatically and effortlessly gets full shell completions that
are perfectly up to date with the active version. When running out of a
git check out this is a big improvement over shtab since completions Just
Work with no need to specially manage the shtab files.

The boilerplate is setup so the argcomplete module is optional, if the
user has it installed (and presumably enabled it for their shell) then it
is activated.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 b4.sh             | 1 +
 src/b4/command.py | 7 +++++++
 2 files changed, 8 insertions(+)

diff --git a/b4.sh b/b4.sh
index e3fbb100be0f98..e47c5b68dbe6da 100755
--- a/b4.sh
+++ b/b4.sh
@@ -1,4 +1,5 @@
 #!/usr/bin/env bash
+# PYTHON_ARGCOMPLETE_OK
 #
 # Run b4 from a git checkout.
 #
diff --git a/src/b4/command.py b/src/b4/command.py
index 8a8c96f635af67..803ed333346372 100644
--- a/src/b4/command.py
+++ b/src/b4/command.py
@@ -1,4 +1,5 @@
 #!/usr/bin/env python3
+# PYTHON_ARGCOMPLETE_OK
 # -*- coding: utf-8 -*-
 # SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (C) 2020 by the Linux Foundation
@@ -1331,6 +1332,12 @@ def setup_parser() -> argparse.ArgumentParser:
 
 def cmd() -> None:
     parser = setup_parser()
+    try:
+        import argcomplete
+        argcomplete.autocomplete(parser)
+    except ImportError:
+        pass
+
     cmdargs = parser.parse_args()
     logger.setLevel(logging.DEBUG)
 

base-commit: 362b87aa4d036884c36e4bfb9cdbdee626aba3bf
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-08-12 20:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-07 23:17 [PATCH b4] Support python argcomplete Jason Gunthorpe
2026-08-11 23:28 ` Konstantin Ryabitsev
2026-08-12 20:59   ` Jason Gunthorpe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox