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

Allow to only run command when given pattern is matched #17

Open
ngirard opened this issue Jan 14, 2021 · 2 comments
Open

Allow to only run command when given pattern is matched #17

ngirard opened this issue Jan 14, 2021 · 2 comments

Comments

@ngirard
Copy link

ngirard commented Jan 14, 2021

Hi and happy new year,

Given the most general running scenario involving a pattern

rargs -p <pattern> <cmd>

I'm unsure whether it makes sense to run cmd no matter if the pattern is matched ; but at least I can tell that it is not always what I expect from Rargs.

Take for instance the common scenario when some files, e.g.

1. Some name
10. Another name

need to be renamed like

01. Some name
10. Another name

There, I wish I was able to type

ls |rargs -p '^(\d\..*)' -- mv "'{1}'" "'0{1}'"

but it wouldn't currently work since Rargs would execute mv for both files, instead of the first one only.

@lotabout
Copy link
Owner

@ngirard What about filter by grep? For example

ls | grep '^\(\d\..*\)' | rargs mv "'{1}'" "'0{1}'"

@ngirard
Copy link
Author

ngirard commented Jan 14, 2021

@lotabout, thanks for your comment.
Sure, there are plenty of alternatives here, including command-line tools dedicated to file renaming.

I was hoping that I could count on Rargs in cases like that, because I keep it in my personal toolkit, and the smaller the kit the more likely I am to actually use them efficiently.

Your solution makes sense, but I'd find it cumbersome to leverage, compared with using Rargs only.

I was thinking of something like an additional

-m | --if-match

option, so that it's possible to express e.g.

output | rargs -p pattern --if-match command

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants