Closed c-cube closed 10 months 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.)
@wbolster good points to think about and will be helpful as context when I encounter related issues :), thanks!
@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
.
@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.
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.
@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.
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).
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?