Linux maintainer tooling and workflows
 help / color / mirror / Atom feed
From: Emil Velikov via B4 Relay <devnull+emil.l.velikov.gmail.com@kernel.org>
To: tools@kernel.org
Cc: Konstantin Ryabitsev <konstantin@linuxfoundation.org>,
	 Emil Velikov <emil.l.velikov@gmail.com>
Subject: [PATCH b4] b4: add shell completion via python-shtab
Date: Tue, 27 Feb 2024 13:18:24 +0000	[thread overview]
Message-ID: <20240227-shell-completion-v1-1-a809aad38589@gmail.com> (raw)

From: Emil Velikov <emil.l.velikov@gmail.com>

The python-shtab module allows for static shell completion files,
whereas others like python-argcomplete, execute the underlying tool for
ever suggestion.

Currently it supports bash, zsh and tcsh - maintainer is open to patches
supporting fish.

In addition, the action completion (aka is the argument is a folder,
file, git sha, etc) is non-existing, but even as-is the completions are
quite useful.

To generate/install the zsh completion use:
 - ./b4.sh --print-completion zsh > _b4
 - mv _b4 /usr/share/zsh/site-functions/_b4

For more details, see the website https://github.com/iterative/shtab

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
---
As with any tool, having shell completion is a must both to improve
productivity and improve ramp-up for noobies.

Initially I started off writing zsh completion by hand, although the
100+ options quickly made me reconsider my life choices :-D

Instead we can use python-shtab, which:
 - is an amazing starting point
 - requires effectively zero maintenance by the b4 team

I have been using the zsh completion for a few weeks now and it works
fine. From a quick test the bash completion is also quite decent.

If needed, the generated files can be checked into the git repo and
expanded on. Even though personally I don't think that's a great idea.

Happy to do so, of course - let me know either way.
---
 src/b4/command.py | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/b4/command.py b/src/b4/command.py
index be0f033..10cb4d0 100644
--- a/src/b4/command.py
+++ b/src/b4/command.py
@@ -363,6 +363,13 @@ def setup_parser() -> argparse.ArgumentParser:
                           help='Submit the token received via verification email')
     sp_send.set_defaults(func=cmd_send)
 
+    try:
+        import shtab
+
+        shtab.add_argument_to(parser, ["-s", "--print-completion"])
+    except ImportError:
+        pass
+
     return parser
 
 

---
base-commit: 7f3284906e67f138eae82271a6c3bde1ebb30791
change-id: 20240227-shell-completion-060a610f5b20

Best regards,
-- 
Emil Velikov <emil.l.velikov@gmail.com>


                 reply	other threads:[~2024-02-27 13:18 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=20240227-shell-completion-v1-1-a809aad38589@gmail.com \
    --to=devnull+emil.l.velikov.gmail.com@kernel.org \
    --cc=emil.l.velikov@gmail.com \
    --cc=konstantin@linuxfoundation.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).