Linux maintainer tooling and workflows
 help / color / mirror / Atom feed
* [PATCH b4 v2] b4: add shell completion via python-shtab
@ 2024-03-01 16:59 Emil Velikov via B4 Relay
  2024-03-01 17:38 ` Konstantin Ryabitsev
  2024-03-05 20:53 ` Konstantin Ryabitsev
  0 siblings, 2 replies; 6+ messages in thread
From: Emil Velikov via B4 Relay @ 2024-03-01 16:59 UTC (permalink / raw)
  To: tools; +Cc: Konstantin Ryabitsev, Emil Velikov

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.

Static completion files are a cleaner solution and also faster to
execute. So we're going with them.

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

Although currently there is no completion action, although that's rather
rare with b4 so we can live without out.

My completion action, we're talking about the automatic hints such as
folders (for example with `b4 sen -o some-folder/`) and alike.

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>
---
Having a shell completion is cool way to ramp-up and improve your
workflow with any tool.

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

Shortly afterwards, I found python-shtab which seems to work just fine.
Since it's effectively a zero maintenance I opted for that, instead of
completing the hand-written ones.

Both zsh and bash completions work fine in my testing, although YMMV.

Ideally, distro maintainers will generate those as part of the
packaging. Although if b4 devs prefer having those in-tree that's also
doable.

Happy to do so, of course - let me know either way.

Changes in v2:
- Fix typos and broken grammar
- Document in the README
- Link to v1: https://msgid.link/20240227-shell-completion-v1-1-a809aad38589@gmail.com
---
 README.rst        | 14 ++++++++++++++
 src/b4/command.py |  7 +++++++
 2 files changed, 21 insertions(+)

diff --git a/README.rst b/README.rst
index 20577e4..bd3d00b 100644
--- a/README.rst
+++ b/README.rst
@@ -44,6 +44,20 @@ following commands after the initial clone::
     git submodule update --init
     python3 -m pip install -r requirements.txt
 
+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 generate a completion file, install python-shtab and execute::
+
+    ./b4.sh --print-completion zsh > _b4
+    mv _b4 /usr/share/zsh/site-functions/_b4
+
+You may need to adjust the path and filename, depending on your distribution
+setup and shell used.
+
 Support
 -------
 For support or with any other questions, please email tools@kernel.org,
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>


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

end of thread, other threads:[~2024-03-28 19:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-01 16:59 [PATCH b4 v2] b4: add shell completion via python-shtab Emil Velikov via B4 Relay
2024-03-01 17:38 ` Konstantin Ryabitsev
2024-03-05 20:53 ` Konstantin Ryabitsev
2024-03-06 12:03   ` Emil Velikov
2024-03-06 19:35     ` Konstantin Ryabitsev
2024-03-28 19:59       ` Emil Velikov

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