Skip to content
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

A readline flag #180

Closed
ticki opened this issue Oct 14, 2016 · 9 comments
Closed

A readline flag #180

ticki opened this issue Oct 14, 2016 · 9 comments
Labels
question An issue that is lacking clarity on one or more points.

Comments

@ticki
Copy link

ticki commented Oct 14, 2016

Regular expressions do not work well together with shells, due to escapes, canonicalization, and parsing. I suggest that a flag for reading a line from the user (-r or -R) and using this as the regex, effectively bypassing the shell weirdness.

This could possibly even be the behavior when no argument is given.

@kaushalmodi
Copy link
Contributor

kaushalmodi commented Oct 14, 2016

Probably related to this? #102

If so, this (#102 (comment)) is the solution.

@BurntSushi
Copy link
Owner

Could you please provide a use case that motivates this feature? What does this provide that single quotes or even $'...' don't?

@ticki
Copy link
Author

ticki commented Oct 14, 2016

It's faster to type.

@BurntSushi
Copy link
Owner

BurntSushi commented Oct 14, 2016

@ticki I'd like some examples please. I'm particularly interested in examples that are common.

Are there other tools that implement this particular feature? I can't recall seeing it before.

@BurntSushi
Copy link
Owner

Another problem I kind of have with this feature is that it breaks shell history. When I run a grep or an rg command, I often need to run it multiple times because I need to tweak my pattern or change some other setting. If I have to re-type the regex every time, I'm going to get annoyed pretty quickly.

I do agree that handling escapes is annoying, although I'm not sure how often it comes up in practice. I'd appreciate some brainstorming with other ways to fix this. One idea is #7, although committing the pattern to a file is a bit heavyweight just to avoid escapes, but it does not suffer from the shell history problem (because I can just edit the file).

@BurntSushi BurntSushi added the question An issue that is lacking clarity on one or more points. label Oct 14, 2016
@BurntSushi
Copy link
Owner

BurntSushi commented Oct 15, 2016

I was thinking about this last night before bed. So I guess it doesn't necessarily have to break shell history. If you did:

$ rg --readline hi <<EOF
\w+
EOF

Then scrolling back to this command will preserve the heredoc, which I think satisfies at least one important objection to this feature. It does however mean that you can't search stdin with this feature enabled, which kind of seems like another stumbling block to me.

@zokier
Copy link

zokier commented Oct 23, 2016

If #7 is resolved then you could handle -f- as "read patterns from stdin", which is what GNU grep does. In grep the interaction with searching stdin seems buggy/weird, but I don't think that will be much of a problem in practice.

@BurntSushi
Copy link
Owner

OK, I'm closing this in favor of doing #7 with support for stdin.

@BurntSushi
Copy link
Owner

BurntSushi commented Nov 18, 2016

@ticki FYI, this is done. This works now (master, will be in next 0.3 release), for example:

$ rg -f-
\p{Lu}\pL!
^D

heredocs work too:

$ rg -f- <<EOF
> \p{Lu}\pL!
> EOF

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question An issue that is lacking clarity on one or more points.
Projects
None yet
Development

No branches or pull requests

4 participants