All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@nvidia.com>
To: tools@kernel.org
Subject: [PATCH b4] Support python argcomplete
Date: Fri,  7 Aug 2026 20:17:32 -0300	[thread overview]
Message-ID: <0-v1-fa59fc5072f8+1cf9c-argcomplete_jgg@nvidia.com> (raw)

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


                 reply	other threads:[~2026-08-07 23:17 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0-v1-fa59fc5072f8+1cf9c-argcomplete_jgg@nvidia.com \
    --to=jgg@nvidia.com \
    --cc=tools@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.