-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
invoke a pager to display results #86
Comments
You might consider passing the I'm a little skeptical about actually calling a pager from within |
Indeed, I will probably alias |
BTW, there is a nice way to invoke pager from rust console CLI: https://gitlab.com/imp/pager-rs it does pager instantiation in a quite clever way |
@ayoshi That is pretty slick. It won't work on Windows though. Doing it only on *nix is an option if we decide to proceed. |
git does it the same way I believe, makes sure that the pager is the parent process. |
+1 from me on having a pager. I like how "git grep" will page the results. Something like that would be nice. I can do:
Mostly works. But it can leave stray colors. As in my prompt becomes green. |
@JohnVillalovos If you use |
@BurntSushi Thanks, that does work :) More typing than I would like. /me lazy ;) But it works! |
@JohnVillalovos Yeah, I have |
um I'm trying to make a shell script for that (better than alias, available in more contexts) #!/bin/sh
rg -p "$@" | less -R (chmod +x that thing and call it as |
Oh.. oh.. 😫 any brown paper bags available? Hint: I made it spawn itself recursively. sigh. |
I also support this feature, missing it badly from ag and git grep. |
@bluss Perhaps as a function instead?
|
I use this in my bin directory, works well #!/bin/sh
~/.cargo/bin/rg -p "$@" | less -RFX |
I like @bluss's approach here. I'm not strongly opposed to adding this into |
I just noticed the need for this and augmented my config-file wrapper to also pipe the output through https://github.com/ssokolow/profile/blob/master/home/.zshrc.d/rg (Feel free to change that. I just needed something quick and didn't think I'd ever use I still think the need for the wrapper is a bit of a wart though, given that, in the abstract, such tools are competing on how convenient they can be and my wrapper feels fundamentally no different than "Oh? You want to ignore stuff in your |
I guess what I don't understand behind the philosophy of trying to use external utilities for paging, is that ripgrep already takes care of some presentation issues through the use of ANSI coloring. |
This is a completely unreasonable request, so I'm just going to nip this one right in the bud: so long as I'm the maintainer, ripgrep will never ever never get a built-in pager. |
From what I remember, (Which would mean that |
Well, rg itself uses colors just fine, so either it's using some other mechanism for Windows, or Windows does support ANSI terminal sequences. I've tried updating I understand the need to keep things simple but it really impairs the usability of rg on Windows when there is a lot of output. |
Simplicity is only part of it. The other part of it is that you're asking me or someone else to build an entire cross platform pager into ripgrep, and then you're asking me to maintain that. It's an unreasonable request not only because it completely violates the principle of responsibility, but that's unreasonable because it would be an ungodly amount of really annoying work. On top of all of that, I don't even know that such a thing is possible in Windows. On coloring... The standard way to color things in Windows is through the various console APIs. It's completely unlike ANSI escape sequences. Instead of putting special codes into the output text, you instead need to: 1) stop writing output, 2) ask the console to change the color to X, 3) write output again and 4) ask the console to change the color back to the setting before X. With that said, Windows 10 has some support for ANSI escape sequences, but it needs to be explicitly enabled. Alternatively, the various MSYS2 terminals for cygwin support ANSI escape sequences.
I've spent a ton of time making ripgrep work well on Windows, but I have to draw the line somewhere. I don't know exactly where it is, but it certainly doesn't include a built-in pager. |
Fair enough, that explains some of the complexity. Maybe by the time I get a new laptop later this year and it's Windows 10 then this becomes a non-issue for me. I certainly don't defend Microsoft's decisions for brain-dead implementations of things that otherwise work very well in Unix-land. Looks like
works for me in my crippled Windows 7 world.... |
FWIW, I don't think ripgrep quite works yet with ANSI support on Windows 10. I think it really needs a champion to make it happen who knows more about how to make it work. You can force ripgrep to emit ANSI escapes with
Oh, I thought you wanted paging with coloring. Disabling coloring is certainly one way of getting rid of the escapes. Although, I do find it interesting that you're seeing ANSI escapes at all in a Windows console. That shouldn't happen.
I won't lie, sometimes I think this way too. But I try hard not to, and try extra hard not to actually say it because it tends to just ruffle everyone's feathers. And Unix has its fair share of strange things too. :-) |
Well, I'd like paging with coloring if I can get it, but I need paging and if the way to do that is disabling coloring, then it works well enough for me.
No idea. I just use |
It's not always Microsoft's fault. For example, they chose ...and, the more layers of backward-compatibility abstraction you drop below, the more POSIX-compatible modern Windows tends to get. (I assume, purely out of practicality.) For example, as far as I've been able to determine, DOS and Windows have accepted ...and kernels of the Windows NT lineage don't use drive letters internally... they're just an artifact of the Win32 API subsystem and it's possible to specify paths using an internal, singly-rooted syntax. (Though, admittedly, that is the one notable exception to the (the NT kernel was written so that Win32, OS/2-compatibie, and POSIX-compliant APIs could be offered as pluggable subsystems and NTFS actually has a POSIX "personality" where, among other things, the only disallowed filename characters are |
Here how I solved this, if others are looking:
For
|
Sure! I'll take this one! 🥨🍻 |
The crate pager is really nice and fits well. I'm gonna use it. Any objections, @BurntSushi? BTW, any further tips are more than appreciated. |
@scorphus I am skeptical. That crate hasn't been updated in 2 years. Here is what I would do:
The implementation of |
The
This is a very shallow (and opinionated) analysis rather than a deep dive, but perhaps it may be of use: The I would consider taking a look at Interestingly, |
Yeah! I've been considering bat's implementation as the one to follow. I've also been using it flawlessly for quite some time. TBH, I didn't look too much into anything else, particularly git's one, although it was suggested — that code frightened me, to say the least. I didn't entirely believe it could really help Thank you for the the links, @wonderfulspam! 🙌 Espcially the last one, I wasn't aware of the idea around a built-in parser for bat, that might be something to consider! |
I think you already pointed out the most important things. I'll try to list a few points that come to my mind right now:
If we ever make this happen, it would be available as a library. Yes. However, most of the features that we would want in |
Gosh, these stubborn developers… Guys, check out vgrep. |
I would like to point out that if you're using PowerShell (regardless of platform), You can also set ripgrep having its own pager would certainly be more convenient, though. |
delta has special support for acting as a pager for ripgrep: see the delta manual section. In addition to paging, this brings two other features:
You use it by piping rg --json 'handle' | delta EDIT Please see update below: #86 (comment) |
Wow, that is pretty slick! Nice work. @dandavison I've added a link to that from ripgrep's README: 595e784 PRs are welcome if you'd like to make wording tweaks! |
Thanks @dandavison's comment! # from this
alias rg='rg -p -i'
# to this function
rg ()
{
env rg --json $@ | delta
} And it works just like how |
@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 |
@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 For more info, please read the Hope that helps, and soon we won't hopefully need to check for & rely on the presence of an external tool |
@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 |
Quick update on delta's ripgrep support: Delta now tries to exactly replicate ripgrep output format, so the idea is that piping
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 |
Beautiful! What terminal are you using? Still see hyperlinks from latest delta broken in Konsole and kitty. |
I use kitty! Hyperlinks worked when I tried them yesterday. |
For fish users wanting to use Delta for your pager, you can add an abbreviation: |
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?The text was updated successfully, but these errors were encountered: