# Colorize matches for git log --grep=pattern?

3 messages from 2017-11-01 to 2017-11-01. Participants: Sebastian Schuberth, Jeff King.
Thread: https://gitlist.dev/t/47089

## Sebastian Schuberth, 2017-11-01 10:57

Subject: Colorize matches for git log --grep=pattern?
Message-ID: <otc9a3$h9a$1@blaine.gmane.org>
URL: https://gitlist.dev/e/otc9a3%24h9a%241%40blaine.gmane.org

```
Hi,

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

     git log -E -i --grep=pattern

in the console output?

Regards,
Sebastian


```

## Jeff King, 2017-11-01 18:50

Subject: Re: Colorize matches for git log --grep=pattern?
Message-ID: <20171101185026.d4ljyywz3fepgoth@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20171101185026.d4ljyywz3fepgoth%40sigill.intra.peff.net
In-Reply-To: <otc9a3$h9a$1@blaine.gmane.org>

```
On Wed, Nov 01, 2017 at 11:57:14AM +0100, Sebastian Schuberth wrote:

> 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

```

## Sebastian Schuberth, 2017-11-01 19:54

Subject: Re: Colorize matches for git log --grep=pattern?
Message-ID: <CAHGBnuPspJ6xsZ9dymet2Woku3PkD9fCHy2qMj7cLACCF3UXLQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAHGBnuPspJ6xsZ9dymet2Woku3PkD9fCHy2qMj7cLACCF3UXLQ%40mail.gmail.com
In-Reply-To: <20171101185026.d4ljyywz3fepgoth@sigill.intra.peff.net>

```
On Wed, Nov 1, 2017 at 7:50 PM, Jeff King <peff@peff.net> wrote:

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

-- 
Sebastian Schuberth

```
