threads / patch / 15025

patchbash-completion: Add non-command git help files to bash-completion

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

## tl;dr

12 messages between Aug 15, 2008 and Aug 16, 2008. Diffs are folded; open one to read it.

replies: 11people: 5as markdown or json

Marcus Griep· Aug 15, 2008, 16:15 UTC · lore

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(-)
Show changes to contrib/completion/git-completion.bash +5 −1
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· Aug 15, 2008, 17:38 UTC · re: Marcus Griep · lore

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

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· Aug 15, 2008, 17:53 UTC · re: Jonathan Nieder · lore

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

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

Jonathan Nieder wrote:
Show 15 quoted lines
> 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· Aug 15, 2008, 17:59 UTC · re: Marcus Griep · lore

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

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(-)
Show changes to contrib/completion/git-completion.bash +5 −1
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· Aug 15, 2008, 18:00 UTC · re: Marcus Griep · lore

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

Marcus Griep <marcus@griep.us> wrote:
Show 6 quoted lines
> 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>
Show 17 quoted lines
> 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· Aug 16, 2008, 09:30 UTC · re: Shawn O. Pearce · lore

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

"Shawn O. Pearce" <spearce@spearce.org> writes:
Show 9 quoted lines
> 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.

Junio C Hamano· Aug 15, 2008, 18:21 UTC · re: Marcus Griep · lore

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

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· Aug 15, 2008, 18:33 UTC · re: Junio C Hamano · lore

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

Junio C Hamano wrote:
Show 9 quoted lines
> 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· Aug 15, 2008, 18:50 UTC · re: Marcus Griep · lore

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

Marcus Griep <marcus@griep.us> writes:
Show 13 quoted lines
> 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· Aug 15, 2008, 19:03 UTC · re: Junio C Hamano · lore

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

Junio C Hamano wrote:
Show 16 quoted lines
> 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· Aug 15, 2008, 20:32 UTC · re: Junio C Hamano · lore

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

On 15 aug 2008, at 20:50, Junio C Hamano wrote:
Show 22 quoted lines
> 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?
Show changes to 2 files +7 −1

builtin-help.c, contrib/completion/git-completion.bash

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· Aug 15, 2008, 21:17 UTC · re: Pieter de Bie · lore

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

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

Show changes to 2 files +8 −1

contrib/completion/git-completion.bash, help.c

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
את.ψο´

← back to recent threads