git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 2/2] completion: add docs on how to add subcommand completions

From
Roland Hieber <rhi@pengutronix.de>
Date
Apr 24, 2024, 21:50 UTC
Message-ID
<20240424215019.268208-2-rhi@pengutronix.de>
In-Reply-To
<20240424215019.268208-1-rhi@pengutronix.de>

It took me more than a few tries and a good lecture of __git_main to understand that the two paragraphs above really only refer to adding completion functions for executables that are not called through git's subcommand magic. Add a few sentences for that case.

Signed-off-by: Roland Hieber <rhi@pengutronix.de>
---
PATCH v2:
 - fix typo and superfluous "-my"
PATCH v1: https://lore.kernel.org/git/20240424210549.256256-2-rhi@pengutronix.de/
---
 contrib/completion/git-completion.bash | 7 +++++++
 1 file changed, 7 insertions(+)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index ffcc55484bcd..603181d53a90 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -40,6 +40,13 @@
 #
 #   __git_complete gk gitk
 #
+# To add completion for git subcommands that live in external scripts,
+# define a function of the form '_git_${subcommand}' while replacing all dashes
+# with underscores, and the main git completion will make use of it.
+# For example, to add completion after 'git do-stuff' (which could e.g. live
+# in /usr/bin/git-do-stuff), name the completion function '_git_do_stuff'.
+# See _git_show, _git_bisect etc. below for more examples.
+#
 # Compatible with bash 3.2.57.
 #
 # You can set the following environment variables to influence the behavior of
-- 
2.39.2
Previous: Roland HieberNext: Patrick Steinhardt
Message 2 of 4 in “completion: add 'symbolic-ref'”
  1. 1/2 completion: add 'symbolic-ref'Roland Hieber, Apr 24, 2024
  2. 2/2 completion: add docs on how to add subcommand completionsRoland Hieber, Apr 24, 2024
  3. Patrick SteinhardtApr 25, 2024
  4. Roland HieberApr 25, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.