BurntSushi / ripgrep

ripgrep recursively searches directories for a regex pattern while respecting your gitignore
The Unlicense
48.26k stars 1.98k forks source link

invoke a pager to display results #86

Closed c-cube closed 10 months ago

c-cube commented 8 years ago

Just tried the tool, it's great (as is the blostpost btw). I'm usually using grep -r foo | less -R for searching (with an alias to get colored output), since there might be several pages of results; rg coloring is nice but is lost if piped into a pager. Would it make sense to invoke a pager automatically if the tool detects that its output is not piped?

wbolster commented 1 year ago
env rg --json $@ | delta

@ryuheechul, for correctness with all file names etc, you should be using this function body:

command rg --json "$@" | delta

(you could also detect whether the output goes to a tty and avoid calling delta in that case, but the exact desired behaviour is subjective.)

ryuheechul commented 1 year ago

@wbolster good points to think about and will be helpful as context when I encounter related issues :), thanks!

krishnakumarg1984 commented 1 year ago

@BurntSushi I wonder if the cross-platform pager crate minus shall be of immediate help. minus is written both as a library and a binary crate, with the library specifically intended for being used as a pager integration with other applications. This is exactly the use case we have here, and seems like a perfect fit for the problem we have.

For more info, please read the minus README section on integration with applications as well as this blog post by its author detailing its design and purpose.

Hope that helps, and soon we won't hopefully need to check for & rely on the presence of an external tool delta for paged output from ripgrep.

BurntSushi commented 1 year ago

@krishnakumarg1984 I do not think it's a good idea to depend on external crates like that for core functionality. As soon as I ship something that is based on what minus provides, I've essentially signed up to provide that functionality forever, regardless of whether minus continues to be maintained or not. It also has a very large dependency tree. A significant fraction of ripgrep's dependency tree. There's probably some overlap, but that's not something that inspires confidence from my perspective. Instead, it just increases the risk of having to maintain something else.

dandavison commented 1 year ago

Quick update on delta's ripgrep support:

Delta now tries to exactly replicate ripgrep output format, so the idea is that piping ripgrep --json to delta should be a strictly additive improvement, bringing:

The hyperlinks are particularly convenient if you're using an editor such as VSCode, Pycharm, or IntelliJ that install their own URL handlers for opening links.

Docs: https://dandavison.github.io/delta/grep.html

Please open an issue in the delta repo if delta is failing to emulate the visual appearance of ripgrep output that you would like.

In the image below, the line numbers are OSC8 terminal hyperlinks.

image
ltrzesniewski commented 1 year ago

@dandavison Nice work!

I couldn't find the URI format spec for the JetBrains IDEs, I hope you don't mind if I add the one you've found to #2483 (I'd like for ripgrep to support hyperlinks out of the box).

Did you by any chance find a list of the URI schemes used by the other JetBrains IDEs besides IntelliJ and PyCharm? If not, they should be rather easy to guess, but I can install them all just to make sure.

BurntSushi commented 10 months ago

I think while I had said my stance on this softened a while back, I'm ultimately going to pass on this. I think this is a good example of scope creep, and that ripgrep just does not benefit much from having a --pager flag when users can invoke a pager themselves (or write an alias to do it for them).