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

Feature request: add a command-line option to force case-sensitive search #124

Closed
jeberger opened this issue Sep 28, 2016 · 9 comments
Closed

Comments

@jeberger
Copy link

Rationale: I would prefer smart case to be the default. I can get that by creating an alias like alias rg="rg -S" but then I need some way to force case-sensitive search when I need it e.g. rg --case-sensitive, which given the alias would become rg -S --case-sensitive, the last given flag would then override previous flags.

@BurntSushi
Copy link
Owner

Should it also override the -i flag?

On Sep 28, 2016 3:30 AM, "jeberger" notifications@github.com wrote:

Rationale: I would prefer smart case to be the default. I can get that by
creating an alias like alias rg="rg -S" but then I need some way to force
case-sensitive search when I need it e.g. rg --case-sensitive, which
given the alias would become rg -S --case-sensitive, the last given flag
would then override previous flags.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#124, or mute the thread
https://github.com/notifications/unsubscribe-auth/AAb34golU18VZzSkNELICyf0zP2fxOJgks5quheOgaJpZM4KIf8v
.

@kaushalmodi
Copy link
Contributor

Should it also override the -i flag?

Is it possible to have the last flag win? The idea is to allow a user to override whatever is in the alias.

  • rg -S --case-sensitiverg --case-sensitive
  • rg --case-sensitive -Srg -S
  • rg -S -irg -i
  • rg -i --case-sensitiverg --case-sensitive
  • and so on.. (you get the idea :))

@BurntSushi
Copy link
Owner

Sadly, no, although I agree that might be more intuitive. We'd probably have to switch arg parsing libraries. Docopt doesn't expose that kind of information.

@lespea
Copy link

lespea commented Sep 28, 2016

Just a thought... most of the time this won't happen so if you detect both flags as being set you could just loop through argv and manually take the last one? Not very clean but it would work without requiring a new library.

@BurntSushi
Copy link
Owner

Yeah, I don't really want to add that implementation complexity. We should either do it right (switch to a different arg parsing library, which I don't really want to do) or just specify a precedence.

Let's punt on "last flag wins for now" and decide on precedence. I feel like the precedence should be:

  • --case-sensitive
  • --case-insensitive
  • --smart-case

where flags earlier in the list override flags later in the list.

@kaushalmodi
Copy link
Contributor

kaushalmodi commented Sep 28, 2016

That precedence will work for my use case too where I have --smart-case in the alias.

On a different note. Would you also please add -s as an alias to --case-sensitive?

Update:

because I like tables :)

--case-sensitive > --case-insensitive (-i) > --smart-case (-S)

|---------------------+--------------------+---------------------|
| Alias               | Extra arg to alias | Effective           |
|---------------------+--------------------+---------------------|
| rg -S               | --case-sensitive   | rg --case-sensitive |
| rg -S               | -i                 | rg -i               |
| rg -i               | --case-sensitive   | rg --case-senstive  |
| rg -i               | -S                 | rg -i               |
| rg --case-sensitive | -i                 | rg --case-sensitive |
| rg --case-sensitive | -S                 | rg --case-sensitive |
|---------------------+--------------------+---------------------|

@jeberger
Copy link
Author

Since we can't have "last flag wins", that precedence would be fine. And +1 for the short alias for --case-sensitive.

@BurntSushi
Copy link
Owner

This is done and will be in the next release. I implemented the precedence rules discussed here and made -s alias --case-sensitive.

@gomesalexandre
Copy link

Thank you! Made case-insensitive my default :Rg binding, this is really helpful when having to case-sensitive search ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants