git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RFC PATCH] bash completion: complete refs for git-grep

From
Thomas Rast <trast@student.ethz.ch>
Date
Oct 7, 2009, 15:27 UTC
Message-ID
<200910071727.50770.trast@student.ethz.ch>
In-Reply-To
<20091006154555.GN9261@spearce.org>
Shawn O. Pearce wrote:
Show 17 quoted lines
> 
> Thomas Rast <trast@student.ethz.ch> wrote:
> > +	local i c=1 have_regex=""
> > +	while [ $c -lt $COMP_CWORD ]; do
> > +		i="${COMP_WORDS[c]}"
> > +		case "$i" in
> > +		-e) ;;
> > +		-e*) have_regex="$c" ; break ;;
> > +		-*) ;;
> > +		*) have_regex="$c"; break ;;
> > +		esac
> > +		c=$((++c))
> > +	done
> 
> What happens with `git grep -e a -e b`?  Do we trigger into ref
> completion too early when we should still be doing the regex
> completion?

Hmm, true, I would also have to check for the last argument (before completion) being -e.

However, that is kind of moot because we currently complete filenames anyway, and you said I can't stop that:

Show 9 quoted lines
> > This is still RFC because, as you can see in the code below, I tried
> > to avoid completing at all while the user still needs to supply a
> > regex.  Sadly, bash turns the COMPREPLY=() into filename completion
> > anyway.  Is there a way to prevent this?
> 
> Not that I know of.  You can turn off default filename completion
> when you register the completion function, but that then breaks
> like every other git command for completion support because a lot
> of them do want to complete filenames.

So I'll roll a simpler patch that just always (before --) completes refs instead, if that's ok.

-- 
Thomas Rast
trast@{inf,student}.ethz.ch
Previous: Shawn O. PearceNext: Thomas Rast
Message 3 of 6 in “bash completion: complete refs for git-grep”
  1. bash completion: complete refs for git-grepThomas Rast, Oct 6, 2009
  2. Shawn O. PearceOct 6, 2009
  3. Thomas RastOct 7, 2009
  4. bash completion: complete refs for git-grepThomas Rast, Oct 12, 2009
  5. Shawn O. PearceOct 12, 2009
  6. Junio C HamanoOct 12, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.