Skip to contentSkip to conversation

Colorize matches for git log --grep=pattern?

DISCUSSION Sebastian Schuberth 2 participants 3 messages Nov 1, 2017

lore
Share & tools
lore
#0 lore raw

Hi,

is there a way to colorize / highlight the pattern matched by

    git log -E -i --grep=pattern

in the console output?

Regards,
Sebastian

#1 lore raw
Quoted 5 lines · Sebastian Schuberth

is there a way to colorize / highlight the pattern matched by

    git log -E -i --grep=pattern

in the console output?

I don't think so. The grep code _does_ know about colorizing matches (which is why "git grep --color" works), but for the output code path for commit messages doesn't use grep at all (it couldn't, because we're not just showing the relevant lines but selecting the whole commit).

So I think it would have to be reimplemented separately.

The best workaround I could come up with is passing the output through a highlighting script:

  git log --grep=foo --color |
  perl -pe 's/foo/\x1b[1;31m$&\x1b[m/' |
  less

Pretty hacky.

-Peff

#2 lore raw
Quoted 8 lines · Jeff King

The best workaround I could come up with is passing the output through a highlighting script:

  git log --grep=foo --color |
  perl -pe 's/foo/\x1b[1;31m$&\x1b[m/' |
  less

Pretty hacky.

Thanks anyway. I was also considering something like this, but likewise found it to be too hacky.

Signature · 1 line
Sebastian Schuberth