threads / discuss / 62724

Change the grep command called by git with alternative tools, such as ug.

Subject: Change the grep command called by git with alternative tools, such as ug.

## tl;dr

5 messages between Jan 2, 2025 and Jan 2, 2025.

replies: 4people: 3as markdown or json

Hongyi Zhao· Jan 2, 2025, 11:48 UTC · lore
Hi there,

Can I change the grep command called by git with alternative tools, such as ug [1]?

Say in the following command:
$ git grep -i jobflow
I tried to replace grep with ug, but failed as follows:

$ git ug -i jobflow git: 'ug' is not a git command. See 'git --help'.

The most similar command is
    gui
[1] https://github.com/Genivia/ugrep

Regards, Zhao

-- 
Assoc. Prof. Hongsheng Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
No. 473, Quannan West Street, Xindu District, Xingtai, Hebei province
Matěj Cepl· Jan 2, 2025, 13:00 UTC · re: Hongyi Zhao · lore

Re: Change the grep command called by git with alternative tools, such as ug.

On Thu Jan 2, 2025 at 12:49 PM CET, Hongyi Zhao wrote:
> $ git grep -i jobflow
>
> I tried to replace grep with ug, but failed as follows:

AFAIK, git grep doesn’t use external grep(1) binary on its own, but rather it uses its own (and slightly different) algorithm. Certainly, calling git-ug (or git-rg) will do absolutely nothing as long as you have no git-ug binary in your $PATH.

Best,
Matěj
-- 
http://matej.ceplovi.cz/blog/, @mcepl@en.osm.town
GPG Finger: 3C76 A027 CA45 AD70 98B5  BC1D 7920 5802 880B C9D8
 
When God put a calling on your life, He already factored in your
stupidity.
  -- Unknown, mentioned in a sermon
Hongyi Zhao· Jan 2, 2025, 13:39 UTC · re: Matěj Cepl · lore

Re: Change the grep command called by git with alternative tools, such as ug.

On Thu, Jan 2, 2025 at 9:00 PM Matěj Cepl <mcepl@cepl.eu> wrote:
Show 11 quoted lines
>
> On Thu Jan 2, 2025 at 12:49 PM CET, Hongyi Zhao wrote:
> > $ git grep -i jobflow
> >
> > I tried to replace grep with ug, but failed as follows:
>
> AFAIK, git grep doesn’t use external grep(1) binary on its
> own, but rather it uses its own (and slightly different)
> algorithm. Certainly, calling git-ug (or git-rg) will do
> absolutely nothing as long as you have no git-ug binary in your
> $PATH.
Do you mean: by linking ug as git-ug will do the trick?
> Best,
>
> Matěj
Zhao
Matěj Cepl· Jan 2, 2025, 14:57 UTC · re: Hongyi Zhao · lore

Re: Change the grep command called by git with alternative tools, such as ug.

On Thu Jan 2, 2025 at 2:39 PM CET, Hongyi Zhao wrote:
> Do you mean: by linking ug as git-ug will do the trick?

No, you would have to rewrite git-grep to use external grep-like program. I am not sure whether there isn’t such project already out there.

Best,
Matěj
-- 
http://matej.ceplovi.cz/blog/, @mcepl@en.osm.town
GPG Finger: 3C76 A027 CA45 AD70 98B5  BC1D 7920 5802 880B C9D8
 
To the well-organized mind, death is but the next great adventure.
  -- Albus Dumbledore
Jonathan Nieder· Jan 2, 2025, 15:28 UTC · re: Matěj Cepl · lore

Re: Change the grep command called by git with alternative tools, such as ug.

Hi,
Matěj Cepl wrote:
> On Thu Jan 2, 2025 at 2:39 PM CET, Hongyi Zhao wrote:
Show 5 quoted lines
>> Do you mean: by linking ug as git-ug will do the trick?
>
> No, you would have to rewrite git-grep to use external grep-like
> program. I am not sure whether there isn’t such project already
> out there.

The key question is - what are you trying to do? "git grep" is able to search inside historical commits, the working copy, the index, and so on. Do we want to search in the same way to find files with hits (for efficiency reasons, for example) and then use an external program to find the matches within those files? For that kind of application I might do some scripting around "git grep --name-only", but I can also imagine that your application is different. Depending on the goal, it could be something a git command already supports, an implied feature request for git, or something that the external search tool might need to learn.

In other words, Matěj's reply is spot on in describing the current behavior: "git grep" doesn't call out to an external grep tool. But as for the desired behavior, we'd need to know more about the use case to figure it out.

Thanks, Jonathan

← back to recent threads