-
-
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
Searching filenames (-g
option in ag
)
#91
Comments
I'm pretty sure this has been reported at least several times now. :-) |
Sorry about that! It might be indicative of a documentation "bug"; it seems people are having trouble locating this feature. |
Ah, I get it now. It's a combination of two flags: This is very non-obvious. It requires users to fully understand two separate, unrelated options and to realize that when combined, they can be used to solve their problem. Since ripgrep will have lots of users coming from ag who will expect a simple single-flag solution, it might be a good idea to have a single flag (much like ag) for this use-case, if for any reason, than to save you the headache of closing all these issue reports. :) |
I'd like to solve this with better documentation. It's clear this is an important feature to many, but it's decidedly subservient to ripgrep's primary focus, so I'd like to avoid adding extra flags for it. |
That would be a great feature. But it is important to notice the differences. Let's say I have this directory tree:
So, ideally, if such a feature is implemented in ripgrep to reproduce what The Silver Search does, it should check the path (not only the name) and also match any part of the string (not an exact match, not a glob). |
Remember that |
In case somebody wouldn't know the syntax for doing a search with the condition of excluding files with a certain name using the command line, here is an example to do so:
As shown, you may need to escape |
Or just use single quotes.
…On Dec 26, 2016 11:56 PM, "nateozem" ***@***.***> wrote:
In case somebody wouldn't know the syntax for doing a search with the
condition of excluding files with a certain name using the command line,
here is an example to do so:
$ rg "from_str" -g "\!tags" -g "repos/*"
^^^
As shown, you may need to escape ! with \, if wish to exclude files from
search.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#91 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAb34sr7aMsWRt2-EZ0DUTcu_0dCcxmwks5rMJqIgaJpZM4KGBgW>
.
|
Are there search parameters for rg that would list any files that match Say, for 'python' I'd like to get - Is that possible directly, without parsing the output? |
No. ripgrep will never print directories, only file paths. ripgrep isn't a Note that there's enough of |
Note that
So to replicate |
No. "binary" files isn't a fact one can know without actually searching the file contents.
Those aren't the same.
Whether a file is empty or not has no impact on the output of
|
@BurntSushi
I was referring to |
It does:
Please note that "binary" detection cannot possibly be perfect. It uses a simple heuristic: if there's a
ripgrep is a line oriented searcher. If a file doesn't contain any lines, then there's nothing to match. What is your use case? In the future, could you please open new issues for new bug reports/feature requests? |
And that is good.
I see, but somehow thought that But
I get you, but it is still about mimicking
I was using I've replaced it now with |
Definitely not. I think there is a lot of value in having a similar interface as other tools, but I've never added something to ripgrep just for the sake of mimicking another tool. :-) In the future, please open new issues to discuss new features or bugs. This particular issue is closed and done with. If there's a problem, we should start a new discussion.
Why does this require printing empty files? Surely you won't be able to jump to any symbol defined in an empty file. ;-) |
@BurntSushi
Sure, but then this issue is still the place to come to when you want to simulate it - that's what I've meant. All is fine from my side.. :) |
@blueyed I see, OK. I had a really hard time understanding what you were trying to say! Glad all is well. |
@BurntSushi |
Seems like I misunderstood what Given that, I can't say that |
Is there no combination of flags for ripgrep allowing users to constrain both the filename and the content simultaneously? I'd like to search for Makefile's with "$$" in them, for example. Currently working around this with |
@mcandre What have you tried? If |
@BurntSushi Thanks for the tip, works like a charm! I wonder why the ripgrep CLI parsing doesn't treat
as
Oh well, at least the latter works on my machine^TM. |
Because Might be worth reviewing something like http://www.regular-expressions.info/quickstart.html |
@okdana Lol I totally forgot about that! Yeah, |
@BurntSushi I apologize if you find these kinds of issues annoying, but clearly based on your comments in some of them you understand that a lot of us want this behavior. Your focus up to this point has been on showing that ripgrep already has the behavior, but I think you should heavily consider focusing on making it as easy as it is in Using To be clear I'm not proposing you make it |
@rosshadden What are you actually asking for? The
|
Thanks for the mention of |
I'm trying to achieve what's been discussed on this thread, but it's not working for me, I'm not sure if I've misunderstood something, or if something's broken. Say I want to find files named
What am I doing wrong? With |
@WhyNotHugo The glob is applied to every path ripgrep traverses. Is |
@BurntSushi
|
Please file a new and complete big report. Your comment isn't actionable. |
I solved this as follows: To search Python in filenames:
|
piggybacking off of @anishmittal2020
Put in .bashrc, and then call it on the command line. Taking @WhyNotHugo example:
The first two files will be returned, the first because the path contains a dir called vendor, and the second because it contains a filename with vendor. The last file is a dir, it will not be returned. Edit: I hate to admit it, but I should have just used fd from the get-go. It allows for regex arguments, and user can specify if they want to search for files, directories, or both.
|
I have read the whole thread. I have not successfully managed to just find all filenames containing "helm".
I just finds filenames with detached "helm" (i.e., "xxx-helm-xxx.el"), but not "xxxhelmxxx.el". |
@AtomicNess123 Works just fine for me:
|
Thanks. Actually, it does work in your example.
In this case, when I specify the folder to search within, it only finds the "xxx-helm-xxx.el" instances, and not the "xxxhelmxxx.el" ones. |
Also works just fine:
I can't think of a reason why it isn't working for you. Sorry. To be honest, it doesn't make sense to me why |
I won't work like this in my system.
What is your version? |
Same, but there aren't any recent changes that would impact this AFAIK. Please consider trying my exact set of commands in a fresh directory. Try running with the |
Other question: how many levels (subdirectories) will the command search? |
All... |
Then, it makes no sense. It works in your example. But I want to find any filename with "helm" in the name. If I search from root or any other folder, it only finds the files at the .emacs.d/modules and .emacs.d/other, but not in .emacs.d/elpa. It is very strange. But when I enter the elpa directory and run the command from there, it finds all the files. |
Ok... does .gitignore affect results? It seems elpa is in .gitignore! |
Of course. The first two sentences of the readme:
This is why I suggested the |
Yes, you were right. I'm just newbie in command line functions. I wonder if it's possible to override .gitignore setting? |
Sure. See the guide. If you have a specific question then open a new discussion post. |
Sorry to dig up this issue once again, but as a Windows user I believe workarounds provided earlier are not sterling, because |
Other software being buggy is not something I'm receptive towards as a motivation for adding more features to ripgrep. |
Thanks for this. What is the meaning of "${PWD}"? |
Whats wrong with doing This seems to work fine for me :) |
Inspired by the earlier alias, I'm trying something like this. Function is named ag because old habits die hard 😅
|
Appreciate the snippet! Good to know.
One reason to bake this functionality into rg itself, is that sort may have
different syntax on Windows.
And any sorting is most efficiently done with appropriate data structures
as early as possible (e.g., "online" algorithm), rather than after the fact.
…On Wed, Mar 23, 2022, 3:26 PM James Robey ***@***.***> wrote:
Inspired by the earlier alias, I'm trying something like this. Function is
named ag because old habits die hard 😅
function ag() { rg --files | rg ".*/.*$1.*" | sort | rg $1 }
—
Reply to this email directly, view it on GitHub
<#91 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAABJRGFSUSKJF77H426E3LVBN5AJANCNFSM4CQYDALA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
This makes it possible to preprocess query arguments on the fly. One use case (which is already implemented in this commit) is the transformation of `-Gpattern` to `--iglob=**/*pattern*/**`, which makes it possible to easily restrict rg searches to files containing `pattern` in the path. ag's -g flag probably will never be implemented in rg: BurntSushi/ripgrep#91.
Please excuse the newbie question here: |
@PyKoch Please don't ask questions in old unrelated issues. This issue is a feature request for some other feature. And when you do ask questions, please include a reproduction. Here's how you do it: you include all relevant details so that others can see what you're seeing. This means providing inputs, showing the outputs you see and the outputs you want to see. Basically, it comes down to "show, don't tell." Here, I'll show you. First create an empty directory with some files:
And now run
And now my attempt at filtering:
If you did that, then folks helping you wouldn't have to guess at your problem. The first thing to realize here is that ripgrep isn't printing any files. This seems different from what you report where there are files being printed. Since you didn't share any details about your environment, and you provided a command more complex than necessary to demonstrate your specific issue with filtering out things that contain In any case, there are two issues here. Assuming you're on Unix, the first issue is that you're escaping
In the future, please don't ask questions in old issues. There's an entire discussion forum open for that purpose. |
Ag supports using
-g
to recursively search filenames matching the provided pattern. Ripgrep doesn't have this feature (to the best of my knowledge; I've read the--help
output three times looking for it); it's the only ag feature holding me back from fully switching to ripgrep. :)Since ripgrep already has something unrelated mapped to
-g
, the option name should be something else. The incompatibility with ag will be unfortunate, but survivable.The text was updated successfully, but these errors were encountered: