git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Roland Hieber <rhi@pengutronix.de>
To: git@vger.kernel.org
Cc: Roland Hieber <rhi@pengutronix.de>,
	Felipe Contreras <felipe.contreras@gmail.com>,
	Junio C Hamano <gitster@pobox.com>
Subject: [PATCH v3 2/3] completion: improve docs for using __git_complete
Date: Thu, 25 Apr 2024 12:18:43 +0200	[thread overview]
Message-ID: <20240425101845.708554-2-rhi@pengutronix.de> (raw)
In-Reply-To: <20240425101845.708554-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 really only refer to adding
completion functions for executables that are not called through git's
subcommand magic. Improve the docs and be more specific.

Signed-off-by: Roland Hieber <rhi@pengutronix.de>
---
PATCH v3: new in v3, based on feedback from Junio C Hamano
---
 contrib/completion/git-completion.bash | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 4d63fb6eeaf7..566f32d412ce 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -31,15 +31,22 @@
 # Note that "git" is optional --- '!f() { : commit; ...}; f' would complete
 # just like the 'git commit' command.
 #
-# If you have a command that is not part of git, but you would still
-# like completion, you can use __git_complete:
+# If you have a shell command that is not part of git (and is not called as a
+# git subcommand), but you would still like git-style completion for it, use
+# __git_complete. For example, to use the same completion as for 'git log' also
+# for the 'gl' command:
 #
 #   __git_complete gl git_log
 #
-# Or if it's a main command (i.e. git or gitk):
+# Or if the 'gk' command should be completed the same as 'gitk':
 #
 #   __git_complete gk gitk
 #
+# The second parameter of __git_complete gives the completion function; it is
+# resolved as a function named "$2", or "__$2_main", or "_$2" in that order.
+# In the examples above, the actual functions used for completion will be
+# _git_log and __gitk_main.
+#
 # Compatible with bash 3.2.57.
 #
 # You can set the following environment variables to influence the behavior of
-- 
2.39.2



  reply	other threads:[~2024-04-25 10:19 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-25 10:18 [PATCH v3 1/3] completion: add 'symbolic-ref' Roland Hieber
2024-04-25 10:18 ` Roland Hieber [this message]
2024-04-25 10:18 ` [PATCH v3 3/3] completion: add docs on how to add subcommand completions Roland Hieber
2024-04-25 10:45 ` [PATCH v3 1/3] completion: add 'symbolic-ref' Kristoffer Haugsbakk
2024-04-25 14:36   ` Justin Tobler
2024-04-25 16:42     ` Junio C Hamano
2024-04-25 21:40       ` Justin Tobler
2024-04-25 21:48         ` Junio C Hamano
2024-04-25 16:50 ` Junio C Hamano
2024-04-26 11:43 ` Patrick Steinhardt

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=20240425101845.708554-2-rhi@pengutronix.de \
    --to=rhi@pengutronix.de \
    --cc=felipe.contreras@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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).