-
-
Notifications
You must be signed in to change notification settings - Fork 824
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
RFC: --exec with placeholder corresponding to regex groups/ocurrences #1118
base: master
Are you sure you want to change the base?
Conversation
Thank you for your contribution and especially for sharing not just an implementation but also use cases and examples. To be frank, I'm rather skeptical. But certainly open to discuss this.
I typically use fd ' copy' -X replace ' copy.*\.' '.' should do the same job... in an (arguably) more descriptive way?
Not exactly sure what that does, but adding prefixes, suffixes, and different extensions should already be possible with the existing placeholders, no? |
Thanks for considering to discuss it and sorry for my examples not being good enough to show the use cases.
You are right that there is alternatives for handling these use cases. Also, the current tricks are still useful. :)
Partially:
But not being able to:
See: ❱ fd 'fixed.*.txt' -x echo "rename fixed adequated {}"
rename fixed adequated ./files/one-fixed-name.txt
❱ cargo run -- '(.*)-(.*)-(.*).txt' -x echo "mv {} {//}/{1}-adequated-{3}.txt"
...
mv ./files/one-dynamic-title.txt ./files/one-adequated-title.txt
mv ./files/such-fixed-name.txt ./files/such-adequated-name.txt For sure that would be possible to use additional tools to solve more complex and more dynamic cases like in this example. For example, one can pipe But having placeholders for substitution of regex matches in I missed this when renaming some music files that had very messy file names. At that time I needed to make many complex changes like inverting the position of the artist with the song name as in this example: ❱ cargo run -- '([^-\n]+)(?:(\s+-\s+)(.+))?(.mp3)' -t f -x echo "{}_{//}/{3:-Unknown} - {1}.mp3" | column -t -s '_'
...
./music/I Still Haven't Found What I'm Looking For - U2.mp3 ./music/U2 - I Still Haven't Found What I'm Looking For.mp3
./music/Time to Love.mp3 ./music/Unknown - Time to Love.mp3
./music/We Will Rock You - Queen.mp3 ./music/Queen - We Will Rock You.mp3
./music/Angie - Rolling Stones.mp3 ./music/Rolling Stones - Angie.mp3
./music/I Will Follow - U2.mp3 ./music/U2 - I Will Follow.mp3
./music/Sunday Bloody Sunday - U2.mp3 ./music/U2 - Sunday Bloody Sunday.mp3
./music/We Are the Champions - Queen.mp3 ./music/Queen - We Are the Champions.mp3
./music/Brown Sugar - Rolling Stones.mp3 ./music/Rolling Stones - Brown Sugar.mp3
./music/Desire - U2.mp3 ./music/U2 - Desire.mp3
./music/One - U2.mp3 ./music/U2 - One.mp3
./music/I Want to Break Free - Queen.mp3 ./music/Queen - I Want to Break Free.mp3
./music/Satisfaction - Rolling Stones.mp3 ./music/Rolling Stones - Satisfaction.mp3
./music/With or Without You - U2.mp3 ./music/U2 - With or Without You.mp3 I hope that these examples let the motivations become clearer. :) |
Hi, I just wanted to express my interest in a feature like this being included in fd. I use fd pretty heavily to select data files from a collection of files for processing. Often we store metadata as path components within our data repository (for example, what sensor it originates from). various scripts we use require this information, so we pass it in with commandline flags. Right now I use short inline bash scripts to parse the information out of the file path and pass it to the scripts, but this is pretty fragile and gross. Anyway, I ran into this older PR researching to see if I could implement a similar feature. I though I would comment because I have a use case that is not file renaming. |
This would be an awesome feature - every now and then I need to make a rename or move based on some pattern within files or directories. This would make such changes kinda trivial/magic! |
What
Allow the groups/occurrences matched by the regex pattern over the filename/path to be used as placeholders for commands executed with the flag
--exec
.Note however that it's just a proof-of-concept yet. I just have written for checking if it could become accepted. The code is far from done but at least it's possible to run and play with any supported regex and the placeholder support.
So, please share your opinion.
Features
Uses cases:
Renaming or moving files and folders:
Adding prefixes, text, and extensions to file names:
Syntax
From the help:
Examples