{"thread":{"id":"21139","subject":"[RFC PATCH] bash completion: complete refs for git-grep","startedAt":"2009-10-06T10:08:12Z","lastAt":"2009-10-12T23:42:02Z","messageCount":6,"participants":["Thomas Rast","Shawn O. Pearce","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"124307","messageId":"14ac499280c9b17f862ab13201b48c64b4827713.1254823328.git.trast@student.ethz.ch","threadId":"21139","inReplyTo":null,"subject":"[RFC PATCH] bash completion: complete refs for git-grep","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2009-10-06T10:08:12Z","receivedAt":"2009-10-06T10:08:12Z","isPatch":true,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"Attempt ref completion once we have seen a regular expression, to help\nthe user with entering the <treeish> arguments.\n\nSigned-off-by: Thomas Rast <trast@student.ethz.ch>\n---\n\nThe use-case for this is actually a bit protracted but came up on IRC\nyesterday: pasky asked if there was a simple way to grep through a\ncertain file in all refs.\n\nTurns out git-grep already has half the required support: when given a\nseries of refs, it prefixes the matches with the ref, so the output is\nalready in a useful format.\n\nSadly it does not appear to support --all, --branches or similar\n(which would be material for a separate patch).  But bash completion\ncan step in here: with M-*, it can expand all possible completions for\nthe current word onto the command line.\n\nThis is still RFC because, as you can see in the code below, I tried\nto avoid completing at all while the user still needs to supply a\nregex.  Sadly, bash turns the COMPREPLY=() into filename completion\nanyway.  Is there a way to prevent this?  Otherwise the regex\ncomplication should probably just go away and we can complete refs\nalways.\n\n\n contrib/completion/git-completion.bash |   18 ++++++++++++++++++\n 1 files changed, 18 insertions(+), 0 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 6fd7e1d..c8cced6 100755\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1048,6 +1048,24 @@ _git_grep ()\n \t\treturn\n \t\t;;\n \tesac\n+\n+\tlocal i c=1 have_regex=\"\"\n+\twhile [ $c -lt $COMP_CWORD ]; do\n+\t\ti=\"${COMP_WORDS[c]}\"\n+\t\tcase \"$i\" in\n+\t\t-e) ;;\n+\t\t-e*) have_regex=\"$c\" ; break ;;\n+\t\t-*) ;;\n+\t\t*) have_regex=\"$c\"; break ;;\n+\t\tesac\n+\t\tc=$((++c))\n+\tdone\n+\n+\tif [ -n \"$have_regex\" ]; then\n+\t\t__gitcomp \"$(__git_refs)\"\n+\t\treturn\n+\tfi\n+\n \tCOMPREPLY=()\n }\n \n-- \n1.6.5.rc2.251.g34f85\n"},{"id":"124317","messageId":"20091006154555.GN9261@spearce.org","threadId":"21139","inReplyTo":"14ac499280c9b17f862ab13201b48c64b4827713.1254823328.git.trast@student.ethz.ch","subject":"Re: [RFC PATCH] bash completion: complete refs for git-grep","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-10-06T15:45:55Z","receivedAt":"2009-10-06T15:45:55Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Thomas Rast <trast@student.ethz.ch> wrote:\n> This is still RFC because, as you can see in the code below, I tried\n> to avoid completing at all while the user still needs to supply a\n> regex.  Sadly, bash turns the COMPREPLY=() into filename completion\n> anyway.  Is there a way to prevent this?\n\nNot that I know of.  You can turn off default filename completion\nwhen you register the completion function, but that then breaks\nlike every other git command for completion support because a lot\nof them do want to complete filenames.\n\n> +\tlocal i c=1 have_regex=\"\"\n> +\twhile [ $c -lt $COMP_CWORD ]; do\n> +\t\ti=\"${COMP_WORDS[c]}\"\n> +\t\tcase \"$i\" in\n> +\t\t-e) ;;\n> +\t\t-e*) have_regex=\"$c\" ; break ;;\n> +\t\t-*) ;;\n> +\t\t*) have_regex=\"$c\"; break ;;\n> +\t\tesac\n> +\t\tc=$((++c))\n> +\tdone\n\nWhat happens with `git grep -e a -e b`?  Do we trigger into ref\ncompletion too early when we should still be doing the regex\ncompletion?\n\n-- \nShawn.\n"},{"id":"124334","messageId":"200910071727.50770.trast@student.ethz.ch","threadId":"21139","inReplyTo":"20091006154555.GN9261@spearce.org","subject":"Re: [RFC PATCH] bash completion: complete refs for git-grep","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2009-10-07T15:27:49Z","receivedAt":"2009-10-07T15:27:49Z","isPatch":true,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"Shawn O. Pearce wrote:\n> \n> Thomas Rast <trast@student.ethz.ch> wrote:\n> > +\tlocal i c=1 have_regex=\"\"\n> > +\twhile [ $c -lt $COMP_CWORD ]; do\n> > +\t\ti=\"${COMP_WORDS[c]}\"\n> > +\t\tcase \"$i\" in\n> > +\t\t-e) ;;\n> > +\t\t-e*) have_regex=\"$c\" ; break ;;\n> > +\t\t-*) ;;\n> > +\t\t*) have_regex=\"$c\"; break ;;\n> > +\t\tesac\n> > +\t\tc=$((++c))\n> > +\tdone\n> \n> What happens with `git grep -e a -e b`?  Do we trigger into ref\n> completion too early when we should still be doing the regex\n> completion?\n\nHmm, true, I would also have to check for the last argument (before\ncompletion) being -e.\n\nHowever, that is kind of moot because we currently complete filenames\nanyway, and you said I can't stop that:\n\n> > This is still RFC because, as you can see in the code below, I tried\n> > to avoid completing at all while the user still needs to supply a\n> > regex.  Sadly, bash turns the COMPREPLY=() into filename completion\n> > anyway.  Is there a way to prevent this?\n> \n> Not that I know of.  You can turn off default filename completion\n> when you register the completion function, but that then breaks\n> like every other git command for completion support because a lot\n> of them do want to complete filenames.\n\nSo I'll roll a simpler patch that just always (before --) completes\nrefs instead, if that's ok.\n\n-- \nThomas Rast\ntrast@{inf,student}.ethz.ch\n"},{"id":"124681","messageId":"9f58ba1e7db9702d1b0594a8016c204e3d50b72f.1255337776.git.trast@student.ethz.ch","threadId":"21139","inReplyTo":"200910071727.50770.trast@student.ethz.ch","subject":"[PATCH] bash completion: complete refs for git-grep","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2009-10-12T09:00:09Z","receivedAt":"2009-10-12T09:00:09Z","isPatch":true,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"Before the --, always attempt ref completion.  This helps with\nentering the <treeish> arguments to git-grep.  As a bonus, you can\nwork around git-grep's current lack of --all by hitting M-*, ugly as\nthe resulting command line may be.\n\nStrictly speaking, completing the regular expression argument (or\noption argument) makes no sense.  However, we cannot prevent _all_\ncompletion (it will fall back to filenames), so we dispense with any\nadditional complication to detect whether the user still has to enter\na regular expression.\n\nSigned-off-by: Thomas Rast <trast@student.ethz.ch>\n---\n\nSorry for taking so long; I was swamped all weekend by, well, the\nweekend. ;-)\n\nI wrote:\n> Shawn O. Pearce wrote:\n> > > This is still RFC because, as you can see in the code below, I tried\n> > > to avoid completing at all while the user still needs to supply a\n> > > regex.  Sadly, bash turns the COMPREPLY=() into filename completion\n> > > anyway.  Is there a way to prevent this?\n> > \n> > Not that I know of.  You can turn off default filename completion\n> > when you register the completion function, but that then breaks\n> > like every other git command for completion support because a lot\n> > of them do want to complete filenames.\n> \n> So I'll roll a simpler patch that just always (before --) completes\n> refs instead, if that's ok.\n\nSo that's what this patch does.\n\n\n contrib/completion/git-completion.bash |    3 ++-\n 1 files changed, 2 insertions(+), 1 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 6fd7e1d..b08cd77 100755\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1048,7 +1048,8 @@ _git_grep ()\n \t\treturn\n \t\t;;\n \tesac\n-\tCOMPREPLY=()\n+\n+\t__gitcomp \"$(__git_refs)\"\n }\n \n _git_help ()\n-- \n1.6.5.61.g35405\n"},{"id":"124703","messageId":"20091012142710.GI9261@spearce.org","threadId":"21139","inReplyTo":"9f58ba1e7db9702d1b0594a8016c204e3d50b72f.1255337776.git.trast@student.ethz.ch","subject":"Re: [PATCH] bash completion: complete refs for git-grep","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-10-12T14:27:10Z","receivedAt":"2009-10-12T14:27:10Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Thomas Rast <trast@student.ethz.ch> wrote:\n> > So I'll roll a simpler patch that just always (before --) completes\n> > refs instead, if that's ok.\n\nHard to argue with that logic.  :-)\n\nAcked-by: Shawn O. Pearce <spearce@spearce.org>\n\n> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\n> index 6fd7e1d..b08cd77 100755\n> --- a/contrib/completion/git-completion.bash\n> +++ b/contrib/completion/git-completion.bash\n> @@ -1048,7 +1048,8 @@ _git_grep ()\n>  \t\treturn\n>  \t\t;;\n>  \tesac\n> -\tCOMPREPLY=()\n> +\n> +\t__gitcomp \"$(__git_refs)\"\n>  }\n\n-- \nShawn.\n"},{"id":"124781","messageId":"7v4oq46uyd.fsf@alter.siamese.dyndns.org","threadId":"21139","inReplyTo":"20091012142710.GI9261@spearce.org","subject":"Re: [PATCH] bash completion: complete refs for git-grep","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-10-12T23:42:02Z","receivedAt":"2009-10-12T23:42:02Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Shawn O. Pearce\" <spearce@spearce.org> writes:\n\n> Thomas Rast <trast@student.ethz.ch> wrote:\n>> > So I'll roll a simpler patch that just always (before --) completes\n>> > refs instead, if that's ok.\n>\n> Hard to argue with that logic.  :-)\n>\n> Acked-by: Shawn O. Pearce <spearce@spearce.org>\n\nThanks.\n\n>\n>> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\n>> index 6fd7e1d..b08cd77 100755\n>> --- a/contrib/completion/git-completion.bash\n>> +++ b/contrib/completion/git-completion.bash\n>> @@ -1048,7 +1048,8 @@ _git_grep ()\n>>  \t\treturn\n>>  \t\t;;\n>>  \tesac\n>> -\tCOMPREPLY=()\n>> +\n>> +\t__gitcomp \"$(__git_refs)\"\n>>  }\n>\n> -- \n> Shawn.\n> --\n> To unsubscribe from this list: send the line \"unsubscribe git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n"}]}