-
-
Notifications
You must be signed in to change notification settings - Fork 815
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
Support multiple --exec <cmd> instances #406
Comments
Thank you very much for the feedback. I definitely see how that could be useful, yes. Maybe supporting multiple Edit: Unfortunately, users would need to use |
I actually ran into this while testing As a workaround for right now, I noticed you can have $> fd -e rs -x bash -c "grep main {} && echo {}"
fn main() {
main.rs |
@asyncsrc Note that that will break if you have filenames with shell punctuation like apostrophes. This is safe though: fd -e rs -x bash -c 'grep main "$1" && echo "$1"' bash {} |
Any progress on this? This would be really useful I think. |
I tried to look into this today, but I think we currently run into a limitation of |
I looked into clap with an eye on adding this feature, and was surprised by the overall size of the project. While I agree that it would be better if clap just did what you needed, there is enough info in the MatchedArg to rebuild multiple commands:
Of course all of the printing, unwrapping, and lossy utf-8'ing are for demo purposes only. If you are ok with this general approach, and ok helping out a rust newb, I can take a stab at adding this feature. |
I tried your snippet, but I don't understand how that would help:
|
The command line you specified doesn't include ';' to terminate the first exec instance. There is no gap in the indices because clap never terminates the first --exec. If you had instead specified That said, I am not sure that always requiring the ';' is good UI. In fact having to escape a semicolon is one of the issues I had with gnu find as a novice. I have some thoughts here that might be worth going into in a separate issue. |
oh, I see. Yeah, not a fan of the semicolon thing either. Especially since it has to be escaped - completely agreed. In You might be right though. We might end up requiring the semicolon. Otherwise,
Please do. |
Are you ok with this general approach for supporting multiple commands? I will enter a separate issue RE semicolons. |
Really depends on how "hacky" this would get. I'd rather wait for |
I don't think it will get too messy. For example in the command line you give, the exec indices would be something like FWIW, I went through the issue in the clap project, and looked at some possible solutions on that side as well. There isn't really a minor change that can be done which will result in a sensible api. Currently clap is treating How about this, I will implement just the argument handling as I described here and submit a PR. If you like it, I will move forward, if not I will go make a PR for clap. Sound good? |
yes - thank you! |
@sharkdp Does it make sense to support just printing the filename to handle the common use case of echoing the file (ie the |
I think that would make sense, that is proposed in the original issue as well, but I created this with multiple I originally didn’t see the need if this was possible:
But the problem I set out to solve was the print case. However since this issue is on the topic of multiple exec it shouldn’t be closed if |
The upstream issue has actually been fixed. Looks like this going to be part of a clap (3, probably?) release soon. |
In the meantime, clap 3 has been released. This should make it possible to implement that feature. |
and `--exec-batch`. Fixes: sharkdp#406
and `--exec-batch`. Fixes: sharkdp#406
and `--exec-batch`. Fixes: sharkdp#406
A small question with this. Is it possible to use |
I believe it actually always behavea like |
Sometimes I run a command in several different matching directories with --exec, but I would like to print each directory for each command that is executed without having to add an intermediate shell just to print the path.
Perhaps adding an option that would print the matched file-name as well as executing the command in
--exec
. I tried with multiple--exec
but it is not allowed, the only workaround I found was to have an intermediate shell.Here is an example (print the git-status in all matching git directories:
I can imagine that there are other use cases where you would want to print the matched file you execute the
-x
command for.The text was updated successfully, but these errors were encountered: