-
-
Notifications
You must be signed in to change notification settings - Fork 816
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
Finding multiple patterns #315
Comments
Thank you for the feedback! I certainly see the need for this, but I'm not sure we should introduce a new command-line argument, given that there is a reasonable solution via Another option to achieve something like this could be the |
Actually, the |
I'm currently not planning to implement this. Going to close this for now, but happy to reconsider if there is a significant interest in this. |
How about
? That reads naturally, and it would make it possible to add a git grep or find style boolean query language at some point. |
Let's reopen this for further discussion. |
Here is a concrete example I just did with
|
I'm definitely against including a full-blown query language with Your use-case can be solved by running
or
Both of which are shorter than the find equivalent (which is not the main issue here though). |
But, maybe we need a non-regexp OR pattern, following is a example, i guess is not so simple to do with fd.
Can we support like this: fd -IH -g '* (????-??-??) [??:??:??].tar' -g '* (????-??-??) [??:??:??].bak' |
OR is actually pretty easy to do with regexes. your example could be done with:
AND is more difficult. |
Yes, i done this like this: fd -HI '.*(\d{4}-\d{2}-\d{2}) [\d{2}:\d{2}:\d{2}].(tar|bak)' I think it more obscurely then find or solution anyway. |
@sharkdp I have a use case where it would be very useful if |
To be honest, I haven't really seen a reasonable use case for AND so far. Please let me know if there are any. Not a theoretical use case. A real world, practical use case. |
@sharkdp commented on Oct 9, 2021, 12:36 AM GMT+3:30:
Searching for terms where one doesn't know their order. This happens frequently for me; E.g., |
@sharkdp I have an Emacs file finder frontend which can use find or fd as backend. This frontend supports a matching style we call "orderless" matching, where you enter multiple words/regexps separated by space. Each of the file paths should match all of these regexps. Currently one can achieve this by transforming the regular expressions "word1.*word2|word2.*word1", which obviously does not scale well. Another alternative for AND filtering is to use pipes and run fd first and then grep for the remaining regexps (or instead of grep post-filter in the frontend), but then one loses the performance advantages of fd. The "orderless" style matching is quite popular in Emacs to quickly filter a set of candidates, since as @NightMachinary mentioned, the huge advantage is that the user does not have to know the order of the words/regexps. If this is a reasonable use case depends on your judgement of course. It seems to me that fd aims more at shell users. But I often get the request to support fd in the Emacs frontend by users who prefer fd instead of find for performance reasons. |
Ok, I'm inclined to accept a feature request to support
|
In fact, i thought most of discuss in this thread is about --or, that means, we can search multi-pattern at one command line more easiler. |
I propose we can add --or for now, and let discuss the usage and necessity of --and. |
To be concrete, a hypothetical |
not equivalent. Because we can use --or with glob-based search |
It's equivalent in the sense that every glob can be converted to a regex |
But in most simple case, glob-based search is more simple than regexp on keystroke |
If fd gets both My understanding is that fd tries to be simpler than find (but at the same time as powerful as feasible). In that sense, I think it's not too much to ask the advanced user who needs On the other hand, there is really no practical way to work around the lack of In #889, I suggested that one could deprecate the specification of paths as arguments (as opposed to IMHO |
This might be off-topic since it's not strictly about patterns per se, but here's a real-world use case for I have some complex Bash projects with several different types of files (executable scripts, helpers, test modules, etc.) and I want to lint them all at once with This is what I'd like to do:
This can be done with
|
You can already do this.
|
Yes, but |
I think that kind of functionality is out of scope for fd, it would basically involve making an expression language similar to what find has, and make fd significantly more complicated. |
I totally understand not wanting to add that kind of complexity, but what about a simple global flag? (Sorry if this has already been proposed and rejected somewhere else). It could be called e.g.
This would probably be easier to implement, and while not as flexible as |
Thank you for your feedback, but I'm not a fan of the What would Another workaround for the OR use case is to simply use multiple
|
Is there any way to search for directories, or files that match specific pattern? If we search for ALL the files and directories, then, yes, Of course, combining two different searches into one stream is not a problem. But why spawn two instances? :) |
I would like to reinforce the case for an AND operator as opposed to a full implementation of boolean logic (see my above comment): I wrote a script (https://gitlab.kwant-project.org/-/snippets/903, consider it in the public domain) that uses fd as a backend to search for files/directories matching a combination of tags. The tags of each file/directory are obtained are obtained from the path by treating slashes and dashes as separators. For example, the file name “pers/2022/bike-repair.org” corresponds to the tags “pers”, “2022”, “bike”, “repair”, as well as “repair.org” (dots are optional tag separators). Now searching for all events involving my friend “Bob” and the activity “climbing” is as quick as running The purpose of this example is not to convince you to organize your home directory in a similar way (although I think that the scheme works very well), but to give one very concrete usage example of fd use where having a way to express an AND relation would be useful. My script has a
|
I added multiple pattern finding: Uthar@19c2495 But it's much slower now, 10x. I'm not a Rust expert, maybe someone will help |
@Uthar I'd like to take a look at the performance problem. How did you benchmark it? |
Wow, 10x slow, is really not acceptable. |
Thank you.
|
Ah... I think I was compiling with I will be using this. But what I did, adding the
|
Simply timing a single run also isn't very reliable for benchmarking. And if you just run the two commands one after another, the first one you run will probably be significantly slower than the second, because the os will probably cache data from the first run and have it available for the second run. https://github.com/sharkdp/fd-benchmarks has some scripts to help benchmark fd with hyperfine. |
closed via #1139 |
I'd like to be able to search for multiple patterns, like with grep's -e argument. It seems (with fd 7.0.0) the only way is to use alternation in the regex pattern, but this can be less clear than multiple arguments, and is harder to build up programmatically.
The text was updated successfully, but these errors were encountered: