How consult invokes grep/ripgrep

I’m interested in the technicalities behind consult-grep and ripgrep. As outlined in How to filter search results with Vertico, everything before the second # (or what you choose) is given as query to grep/ripgrep.

Now let’s say we have a file with the following content:

one two three

and my search prompt is now #three one#two. This prompt matches the file. How is grep/ripgrep invoked here?

As I understand, grep/ripgrep have no option to search for something like grep --and three --and two, the only option with them is to pipe results. So grep three | grep two. Is this what is done?

Not sure why you mention that ripgrep does not allow multiple pattern filtering. I’m also not familiar with the syntax grep --and <pattern>.

Could this be what you’re asking?

$ cat test.txt
one two three

$ grep -e three -e two test.txt
one two three

$ rg -e three -e two test.txt
1:one two three

That --and came from ugrep. Forget that.

grep -e one -e three does not match what I observe using consult grep. When I enter #one three as pattern and have a file:

one two three
one
three

consult-grep gives me only the line with both one and three, while grep gives all three lines, since -e is basically an or.

I straced emacs, and here comes what is passed to ripgrep: -e "^(?=.*one)(?=.*three)"

So basically consult-grep/ripgrep matches against spaces and transforms the individual words into a single regex.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.