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

Add a short option for --no-filename #1185

Closed
sbraz opened this issue Feb 2, 2019 · 9 comments
Closed

Add a short option for --no-filename #1185

sbraz opened this issue Feb 2, 2019 · 9 comments
Labels
question An issue that is lacking clarity on one or more points.

Comments

@sbraz
Copy link

sbraz commented Feb 2, 2019

Hello,
Would it be possible to add a short option for --no-filename?
I can understand that you may not want to use -h like grep to avoid confusion but I think that any short option would be better than none :)

@BurntSushi
Copy link
Owner

Please suggest a short flag that hasn't been used yet.

@sbraz
Copy link
Author

sbraz commented Feb 3, 2019

The only letters which aren't used are:

d
h
k
y
D
G
I
J
K
O
Q
R
V
W
X
Y
Z

Out of which only d, k and y are neither used in lower-case or upper-case.
I think using -h would be nice for consistency with grep (and I guess that we could still use --help to print the help). But if you don't want to use this one, I have no preference.

@BurntSushi
Copy link
Owner

I'm not sold on adding a short option for this flag. With that said, I don't have a good feel for how often it's used, so it's pretty hard to make a decision. However, I do know that short flags are in short supply, and I'd like to be very careful in how we spend our budget there.

To make one thing clear, there is absolutely no way that I'll be changing the behavior of -h. Prescriptively, I think it is a mistake that grep doesn't print help output when the -h flag is used. Descriptively, the behavior of -h and --help in ripgrep is not the same, so we cannot just use --help.

@BurntSushi BurntSushi added the question An issue that is lacking clarity on one or more points. label Feb 3, 2019
@sbraz
Copy link
Author

sbraz commented Feb 3, 2019

I don't have a good feel for how often it's used

Then I guess we should wait and see if anybody else feels like this is needed. All I can say is that I will often do stuff like zgrep pattern somelog-*.gz and I will add -h because the time recorded in the log file is enough and I don't need the filenames.

I think it is a mistake that grep doesn't print help output when the -h flag is used

I totally agree, it's just that I've gotten so used to it…

@lydell
Copy link

lydell commented Feb 10, 2019

Just to provide a usage data point:

I sometimes run stuff like this:

rg 'font-family:\s*([^;]+)' -r '$1' -o --no-filename -tsass | sort | uniq -c | sort -hr

... to find the most common values for the CSS font-family property in a project (or for font-weight, z-index, you name it). From time to time I do similar aggregations for JavaScript and Python code ("extract all such and such from that part of the code base").

So I wouldn't mind a shortcut.

@BurntSushi
Copy link
Owner

I do kind of feel like this might deserve a short flag. But I don't know which to pick.

-h is the obvious choice, since that's what grep uses and is likely what everyone is familiar with. Unfortunately, I am 100% unwilling to change the behavior of -h today.

I'd also like to avoid using a short flag that has both lowercase and uppercase variants available. For example, both -d and -D are unused, which means they could be a convenient way to enable or disable some other feature in the future. Since we already have -H to enable file names and can't use -h, we should pick a flag that has no chance of being paired with something else.

For example, the -J flag is available, and its lowercase variant, -j, controls parallelism with the number of threads. So -j will never need a -J to "negate" it, making it available. Using this logic and the list above, I think that narrows our choices down to the following:

G
I
J
O
Q
R
V
W
X
Z

I don't think I see any obvious mnemonic device here between the flags above and --no-filename. The only one I can think of is -I, which "comes after -H in the alphabet" and is also the second letter in the word filename. grep does have an -I flag, but I don't see ripgrep ever needing to add a similar flag.

@sbraz
Copy link
Author

sbraz commented Apr 3, 2019

Both -I and -J seem fine :)

BurntSushi added a commit that referenced this issue Apr 14, 2019
This flag is commonly used in pipelines and it can be annoying to write
it out every time you need it.

Ideally, we would use -h for this to match GNU grep, but -h is used to
print help output.

Closes #1185
@kastiglione
Copy link
Contributor

Thanks for adding this, I use it a lot

@banool
Copy link

banool commented May 20, 2024

For anyone reading this looking for a super quick answer to what the flags are:

  • -H, --with-filename Print the file path with each matching line.
  • -I, --no-filename Never print the path with each matching line.

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

5 participants