diff mbox series

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

Message ID 20240424210549.256256-2-rhi@pengutronix.de (mailing list archive)
State Superseded
Headers show
Series [1/2] completion: add 'symbolic-ref' | expand

Commit Message

Roland Hieber April 24, 2024, 9:05 p.m. UTC
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>
---
 contrib/completion/git-completion.bash | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Roland Hieber April 24, 2024, 9:17 p.m. UTC | #1
On Wed, Apr 24, 2024 at 11:05:48PM +0200, Roland Hieber wrote:
> 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>
> ---
>  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..f0c8353c1cdb 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 completeion after 'git do-my-stuff' (which could e.g. live

Ah, of course its s/completeion/completion/ …

 - Roland

> +# 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
> 
>
Junio C Hamano April 24, 2024, 9:36 p.m. UTC | #2
Roland Hieber <rhi@pengutronix.de> writes:

> +# 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 completeion after 'git do-my-stuff' (which could e.g. live
> +# in /usr/bin/git-do-stuff), name the completion function '_git_do_stuff'.

You have either an extra "-my", or two "-my"s missing, in the above.

> +# 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
Roland Hieber April 24, 2024, 9:41 p.m. UTC | #3
On Wed, Apr 24, 2024 at 02:36:27PM -0700, Junio C Hamano wrote:
> Roland Hieber <rhi@pengutronix.de> writes:
> 
> > +# 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 completeion after 'git do-my-stuff' (which could e.g. live
> > +# in /usr/bin/git-do-stuff), name the completion function '_git_do_stuff'.
> 
> You have either an extra "-my", or two "-my"s missing, in the above.

Ah, and I deleted one '-my' in the line before sending it…
Will send a v2.

 - Roland

> 
> > +# 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
>
Junio C Hamano April 24, 2024, 10:22 p.m. UTC | #4
Roland Hieber <rhi@pengutronix.de> writes:

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

OK.  Perhaps the two examples also need some more explanation to
save the next person from wasting their time figuring out what they
are trying to say?  That would be a separate topic, but it would be
nice to fix it while our minds are fresh on that issue.

As I already said, modulo confusion around "-my", the patch looks
good to me.

Thanks.
diff mbox series

Patch

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index ffcc55484bcd..f0c8353c1cdb 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 completeion after 'git do-my-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