# [PATCH] bash-completion: Add non-command git help files to bash-completion

12 messages from 2008-08-15 to 2008-08-16. Participants: Marcus Griep, Jonathan Nieder, Shawn O. Pearce, Junio C Hamano, Pieter de Bie.
Thread: https://gitlist.dev/t/15025

## Marcus Griep, 2008-08-15 16:15

Subject: [PATCH] bash-completion: Add non-command git help files to bash-completion
Message-ID: <1218816948-7864-1-git-send-email-marcus@griep.us>
URL: https://gitlist.dev/e/1218816948-7864-1-git-send-email-marcus%40griep.us

```
Git allows access to the gitattributes man page via `git help attributes`,
but this is not discoverable via the bash-completion mechanism.  This
patch adds all current non-command man pages to the completion candidate
list.

Signed-off-by: Marcus Griep <marcus@griep.us>
---

 By adding them to the help completion, man pages such as the tutorials, hooks,
 and .gitattributes are more accessible to random discovery from bash-completion.

 contrib/completion/git-completion.bash |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index c0bf7aa..76d56eb 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -885,7 +885,11 @@ _git_help ()
 		return
 		;;
 	esac
-	__gitcomp "$(__git_all_commands)"
+	__gitcomp "$(__git_all_commands)
+		attributes cli core-tutorial cvs-migration
+		diffcore glossary hooks ignore k modules
+		repository-layout tutorial tutorial-2
+		"
 }
 
 _git_init ()
-- 
1.6.0.rc2.6.g8eda3

```

## Jonathan Nieder, 2008-08-15 17:38

Subject: Re: [PATCH] bash-completion: Add non-command git help files to bash-completion
Message-ID: <Pine.GSO.4.62.0808151234110.17004@harper.uchicago.edu>
URL: https://gitlist.dev/e/Pine.GSO.4.62.0808151234110.17004%40harper.uchicago.edu
In-Reply-To: <1218816948-7864-1-git-send-email-marcus@griep.us>

```
Hi,

Marcus Griep wrote:

> Git allows access to the gitattributes man page via `git help attributes`,
> but this is not discoverable via the bash-completion mechanism.  This
> patch adds all current non-command man pages to the completion candidate
> list.
[...]
> +		diffcore glossary hooks ignore k modules

I think k should be gitk here :)

Regards,
Jonathan

```

## Marcus Griep, 2008-08-15 17:53

Subject: Re: [PATCH] bash-completion: Add non-command git help files to bash-completion
Message-ID: <48A5C29C.5080602@griep.us>
URL: https://gitlist.dev/e/48A5C29C.5080602%40griep.us
In-Reply-To: <Pine.GSO.4.62.0808151234110.17004@harper.uchicago.edu>

```
It can be either.  In a bash-completion list, though, gitk would probably
be more recognizable.  I'll rehash that one.

Jonathan Nieder wrote:
> Hi,
> 
> Marcus Griep wrote:
> 
>> Git allows access to the gitattributes man page via `git help attributes`,
>> but this is not discoverable via the bash-completion mechanism.  This
>> patch adds all current non-command man pages to the completion candidate
>> list.
> [...]
>> +		diffcore glossary hooks ignore k modules
> 
> I think k should be gitk here :)
> 
> Regards,
> Jonathan

-- 
Marcus Griep
GPG Key ID: 0x5E968152
——
http://www.boohaunt.net
את.ψο´

```

## Marcus Griep, 2008-08-15 17:59

Subject: [PATCH v2] bash-completion: Add non-command git help files to bash-completion
Message-ID: <1218823168-1753-1-git-send-email-marcus@griep.us>
URL: https://gitlist.dev/e/1218823168-1753-1-git-send-email-marcus%40griep.us
In-Reply-To: <1218816948-7864-1-git-send-email-marcus@griep.us>

```
Git allows access to the gitattributes man page via `git help attributes`,
but this is not discoverable via the bash-completion mechanism.  This
patch adds all current non-command man pages to the completion candidate
list.

Signed-off-by: Marcus Griep <marcus@griep.us>
---

 By adding them to the help completion, man pages such as the tutorials, hooks,
 and .gitattributes are more accessible to random discovery from bash-completion.

 This patch also incorporates the suggestion that 'gitk' is an easier to grok
 completion than 'k'.

 contrib/completion/git-completion.bash |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index c0bf7aa..158b912 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -885,7 +885,11 @@ _git_help ()
 		return
 		;;
 	esac
-	__gitcomp "$(__git_all_commands)"
+	__gitcomp "$(__git_all_commands)
+		attributes cli core-tutorial cvs-migration
+		diffcore gitk glossary hooks ignore modules
+		repository-layout tutorial tutorial-2
+		"
 }
 
 _git_init ()
-- 
1.6.0.rc3.10.g5a13c

```

## Shawn O. Pearce, 2008-08-15 18:00

Subject: Re: [PATCH v2] bash-completion: Add non-command git help files to bash-completion
Message-ID: <20080815180059.GA17399@spearce.org>
URL: https://gitlist.dev/e/20080815180059.GA17399%40spearce.org
In-Reply-To: <1218823168-1753-1-git-send-email-marcus@griep.us>

```
Marcus Griep <marcus@griep.us> wrote:
> Git allows access to the gitattributes man page via `git help attributes`,
> but this is not discoverable via the bash-completion mechanism.  This
> patch adds all current non-command man pages to the completion candidate
> list.
> 
> Signed-off-by: Marcus Griep <marcus@griep.us>

Acked-by: Shawn O. Pearce <spearce@spearce.org>

> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index c0bf7aa..158b912 100755
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -885,7 +885,11 @@ _git_help ()
>  		return
>  		;;
>  	esac
> -	__gitcomp "$(__git_all_commands)"
> +	__gitcomp "$(__git_all_commands)
> +		attributes cli core-tutorial cvs-migration
> +		diffcore gitk glossary hooks ignore modules
> +		repository-layout tutorial tutorial-2
> +		"
>  }
>  
>  _git_init ()

-- 
Shawn.

```

## Junio C Hamano, 2008-08-15 18:21

Subject: Re: [PATCH] bash-completion: Add non-command git help files to bash-completion
Message-ID: <7v8wuyb0m7.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7v8wuyb0m7.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <1218816948-7864-1-git-send-email-marcus@griep.us>

```
Marcus Griep <marcus@griep.us> writes:

> Git allows access to the gitattributes man page via `git help attributes`,
> but this is not discoverable via the bash-completion mechanism.  This
> patch adds all current non-command man pages to the completion candidate
> list.

I really do not think this belongs to completion.  "git help topics"
perhaps.

```

## Marcus Griep, 2008-08-15 18:33

Subject: Re: [PATCH] bash-completion: Add non-command git help files to bash-completion
Message-ID: <48A5CC07.2040500@griep.us>
URL: https://gitlist.dev/e/48A5CC07.2040500%40griep.us
In-Reply-To: <7v8wuyb0m7.fsf@gitster.siamese.dyndns.org>

```
Junio C Hamano wrote:
> Marcus Griep <marcus@griep.us> writes:
> 
>> Git allows access to the gitattributes man page via `git help attributes`,
>> but this is not discoverable via the bash-completion mechanism.  This
>> patch adds all current non-command man pages to the completion candidate
>> list.
> 
> I really do not think this belongs to completion.  "git help topics"
> perhaps.

I'm not sure I grok what you mean here...  These items are already accessible
from `git help`, they just aren't discoverable through bash-completion without
the patch.

-- 
Marcus Griep
GPG Key ID: 0x5E968152
——
http://www.boohaunt.net
את.ψο´

```

## Junio C Hamano, 2008-08-15 18:50

Subject: Re: [PATCH] bash-completion: Add non-command git help files to bash-completion
Message-ID: <7vvdy29kok.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vvdy29kok.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <48A5CC07.2040500@griep.us>

```
Marcus Griep <marcus@griep.us> writes:

> Junio C Hamano wrote:
>> Marcus Griep <marcus@griep.us> writes:
>> 
>>> Git allows access to the gitattributes man page via `git help attributes`,
>>> but this is not discoverable via the bash-completion mechanism.  This
>>> patch adds all current non-command man pages to the completion candidate
>>> list.
>> 
>> I really do not think this belongs to completion.  "git help topics"
>> perhaps.
>
> I'm not sure I grok what you mean here...  These items are already accessible
> from `git help`, they just aren't discoverable...

That is exactly what I mean.  I do not think bloating shell completion to
enumerate what help topics there are when the user hits "git help <TAB>"
is a good idea to begin with.  It is a maintenance nightmere for one
thing, and it does not help non-bash users.

	$ git help
	$ git help --all

are existing ways for you to get list of "command topics" that you can ask
the help system about, but I do not see a way to ask "git-help, please
tell me what topics that are not git-commands can I ask you about?", hence
my suggestion to add "git help topics".

And if you based "git help <TAB>" completion on the output from such help
subcommand, you would not have to maintain the list of topics yourself in
the completion script, and I would not mind such a patch too much.

```

## Marcus Griep, 2008-08-15 19:03

Subject: Re: [PATCH] bash-completion: Add non-command git help files to bash-completion
Message-ID: <48A5D2EE.4080400@griep.us>
URL: https://gitlist.dev/e/48A5D2EE.4080400%40griep.us
In-Reply-To: <7vvdy29kok.fsf@gitster.siamese.dyndns.org>

```
Junio C Hamano wrote:
> That is exactly what I mean.  I do not think bloating shell completion to
> enumerate what help topics there are when the user hits "git help <TAB>"
> is a good idea to begin with.  It is a maintenance nightmere for one
> thing, and it does not help non-bash users.
> 
> 	$ git help
> 	$ git help --all
> 
> are existing ways for you to get list of "command topics" that you can ask
> the help system about, but I do not see a way to ask "git-help, please
> tell me what topics that are not git-commands can I ask you about?", hence
> my suggestion to add "git help topics".
> 
> And if you based "git help <TAB>" completion on the output from such help
> subcommand, you would not have to maintain the list of topics yourself in
> the completion script, and I would not mind such a patch too much.

Gotcha.  A static list buried in git-completion.bash would be a maintenance
headache.  I can take a look at that some.

Would we also want to look at doing something similar with '--' option
completion, i.e. invoking the command with '-h' to get the usage and long
options, then building the completion list on that rather than the static
lists it uses now?  The one downside to that is that some completions
include trailing '=', which wouldn't be present in a usage list.

-- 
Marcus Griep
GPG Key ID: 0x5E968152
——
http://www.boohaunt.net
את.ψο´

```

## Pieter de Bie, 2008-08-15 20:32

Subject: Re: [PATCH] bash-completion: Add non-command git help files to bash-completion
Message-ID: <B03ECD53-5920-4750-816F-890980C4CBD6@ai.rug.nl>
URL: https://gitlist.dev/e/B03ECD53-5920-4750-816F-890980C4CBD6%40ai.rug.nl
In-Reply-To: <7vvdy29kok.fsf@gitster.siamese.dyndns.org>

```

On 15 aug 2008, at 20:50, Junio C Hamano wrote:

> That is exactly what I mean.  I do not think bloating shell  
> completion to
> enumerate what help topics there are when the user hits "git help  
> <TAB>"
> is a good idea to begin with.  It is a maintenance nightmere for one
> thing, and it does not help non-bash users.
>
> 	$ git help
> 	$ git help --all
>
> are existing ways for you to get list of "command topics" that you  
> can ask
> the help system about, but I do not see a way to ask "git-help, please
> tell me what topics that are not git-commands can I ask you about?",  
> hence
> my suggestion to add "git help topics".
>
> And if you based "git help <TAB>" completion on the output from such  
> help
> subcommand, you would not have to maintain the list of topics  
> yourself in
> the completion script, and I would not mind such a patch too much.

How about something simple like this?

diff --git a/builtin-help.c b/builtin-help.c
index 391f749..a49b5c2 100644
--- a/builtin-help.c
+++ b/builtin-help.c
@@ -446,6 +446,11 @@ int cmd_help(int argc, const char **argv, const  
char *prefix)
                 return 0;
         }

+       if (!strcmp("man-path", argv[0])) {
+               printf("%s\n", GIT_MAN_PATH);
+               return 0;
+       }
+
         switch (help_format) {
         case HELP_FORMAT_MAN:
                 show_man_page(argv[0]);
diff --git a/contrib/completion/git-completion.bash b/contrib/ 
completion/git-completion.bash
index 3396e35..f781661 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -885,7 +885,8 @@ _git_help ()
                 return
                 ;;
         esac
-       __gitcomp "$(__git_all_commands)"
+       __gitcomp "$(ls $(./git help man-path)/man?/* |
+         sed -n 's/^.*\/git-\{0,1\}\(.*\)\.[0-9]$/\1/p')"
  }

```

## Marcus Griep, 2008-08-15 21:17

Subject: Re: [PATCH] bash-completion: Add non-command git help files to bash-completion
Message-ID: <48A5F265.5080905@griep.us>
URL: https://gitlist.dev/e/48A5F265.5080905%40griep.us
In-Reply-To: <B03ECD53-5920-4750-816F-890980C4CBD6@ai.rug.nl>

```
Pieter de Bie wrote:
> How about something simple like this?

Seems to do the job.

> diff --git a/builtin-help.c b/builtin-help.c

Are you working on next? Even though I know next is the new
master. (master is soooo nearly last week. :-P)

I had a slightly different take.  Your completion creates a 'k'
for gitk, which was suggested earlier in the thread suggested 
is a bit harder to grok.  This promotes 'git?' commands to use
'git?' rather than '?' without affecting things otherwise.
---
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index c0bf7aa..0bb0d79 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -885,7 +885,9 @@ _git_help ()
                return
                ;;
        esac
-       __gitcomp "$(__git_all_commands)"
+       __gitcomp "$(ls $(./git help man-path)/man?/* |
+               sed -n -e 's/^.*\/git-\?\(.\{2,\}\)\.[0-9]$/\1/p' \
+                       -e 's/^.*\/git\(.\)\.[0-9]$/git\1/p')"
 }

 _git_init ()
diff --git a/help.c b/help.c
index 3cb1962..d0416e1 100644
--- a/help.c
+++ b/help.c
@@ -717,6 +717,11 @@ int cmd_help(int argc, const char **argv, const char *prefix)
                return 0;
        }

+       if (!strcmp("man-path", argv[0])) {
+               printf("%s\n", GIT_MAN_PATH);
+               return 0;
+       }
+
        switch (help_format) {
        case HELP_FORMAT_MAN:
                show_man_page(argv[0]);
---

What do you think, Junio?  If it works, I'll make this a
normal patch submission.

-- 
Marcus Griep
GPG Key ID: 0x5E968152
——
http://www.boohaunt.net
את.ψο´

```

## Junio C Hamano, 2008-08-16 09:30

Subject: Re: [PATCH v2] bash-completion: Add non-command git help files to bash-completion
Message-ID: <7vskt5gvcy.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vskt5gvcy.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <20080815180059.GA17399@spearce.org>

```
"Shawn O. Pearce" <spearce@spearce.org> writes:

> Marcus Griep <marcus@griep.us> wrote:
>> Git allows access to the gitattributes man page via `git help attributes`,
>> but this is not discoverable via the bash-completion mechanism.  This
>> patch adds all current non-command man pages to the completion candidate
>> list.
>> 
>> Signed-off-by: Marcus Griep <marcus@griep.us>
>
> Acked-by: Shawn O. Pearce <spearce@spearce.org>

I'd honor this Ack for 1.6.0 and will apply the patch as-is, but that does
not mean I do not think this is a wrong approach in the longer run.

```
