[PATCH b4] Support python argcomplete
Jason Gunthorpe <[email protected]>
| Newsgroups | org.kernel.linux.tools |
|---|---|
| Message-ID | <[email protected]> |
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 <[email protected]> --- 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