threads / discuss / 52162

request: add git grep -o option

Subject: request: add git grep -o option

## tl;dr

3 messages between Oct 30, 2019 and Oct 30, 2019.

replies: 2people: 2as markdown or json

Joe Perches· Oct 30, 2019, 19:58 UTC · lore

Instead of duplicating a grep pattern with grep -oh after git grep like this:

$ git grep -P '(?:[a-z0-9_]+_)?for_each(?:_[a-z0-9_]+)?' -- '*.[ch]' | \
  grep -P -oh '(?:[a-z0-9_]+_)?for_each(?:_[a-z0-9_]+)?'

it could be useful to have git grep have the same '-o' option as gnu grep.

Jeff King· Oct 30, 2019, 20:17 UTC · re: Joe Perches · lore

Re: request: add git grep -o option

On Wed, Oct 30, 2019 at 12:58:59PM -0700, Joe Perches wrote:
Show 9 quoted lines
> Instead of duplicating a grep pattern with grep -oh after
> git grep like
> this:
> 
> $ git grep -P '(?:[a-z0-9_]+_)?for_each(?:_[a-z0-9_]+)?' -- '*.[ch]' | \
>   grep -P -oh '(?:[a-z0-9_]+_)?for_each(?:_[a-z0-9_]+)?'
> 
> it could be useful to have git grep have the same '-o' option 
> as gnu grep.
Doesn't it already?
  $ git grep -P -oh '(?:[a-z0-9_]+_)?for_each(?:_[a-z0-9_]+)?'
  for_each
  for_each
  for_each_abbrev
  for_each_builtin
  for_each_string_list_item
  for_each_ut
  [etc...]
It was new in Git v2.19.
-Peff
Joe Perches· Oct 30, 2019, 20:27 UTC · re: Jeff King · lore

Re: request: add git grep -o option

On Wed, 2019-10-30 at 16:17 -0400, Jeff King wrote:
Show 24 quoted lines
> On Wed, Oct 30, 2019 at 12:58:59PM -0700, Joe Perches wrote:
> 
> > Instead of duplicating a grep pattern with grep -oh after
> > git grep like
> > this:
> > 
> > $ git grep -P '(?:[a-z0-9_]+_)?for_each(?:_[a-z0-9_]+)?' -- '*.[ch]' | \
> >   grep -P -oh '(?:[a-z0-9_]+_)?for_each(?:_[a-z0-9_]+)?'
> > 
> > it could be useful to have git grep have the same '-o' option 
> > as gnu grep.
> 
> Doesn't it already?
> 
>   $ git grep -P -oh '(?:[a-z0-9_]+_)?for_each(?:_[a-z0-9_]+)?'
>   for_each
>   for_each
>   for_each_abbrev
>   for_each_builtin
>   for_each_string_list_item
>   for_each_ut
>   [etc...]
> 
> It was new in Git v2.19.

OK, nice. I never actually tried it and I have 2.24. My docs need updating as that option is not mentioned.

← back to recent threads