Closed vitorgalvao closed 5 years ago
Thanks for this @vitorgalvao.
I'll need some help here as I've not used xargs before, is it not something that would be piped, as in find … | xargs | imageoptim
rather than find … | xargs imageoptim
?
Please add some more info/context and I'll do my best to help, thanks.
No, you don’t pipe from xargs
, but to it. The example I gave is correct, and that link explains well what it does.
You may close this if you want, though. I’ve since started using the ImageOptim app for this directly since it behaves correctly in this situation.
Thanks @vitorgalvao, my inexperience with xargs
is showing here. I'll leave this open as it sounds like something that should be supported, so you can also run those images through imagealpha and JPEGmini.
Thanks for the link, that will be useful.
I can have a look at this one. Quick q though, why do you want to null terminate the list from the find command? Is there a special case? thanks
Files with spaces in the name?
@jamesstout Filenames are full of surprises. Piping from find
to xargs
should always be done that way. Look at their respective man
pages and you’ll see they both acknowledge this — the options were essentially made for each other.
I had a stab at this last night. Tricky. When invoked via xargs
, all the files are passed to imageoptim
along with any imageoptim
args. So, you'd need:
xargs
There are ways to tell if you are in a sub-shell, or part of a command expansion, or an interactive shell, but I couldn't find a portable (works in all shells) way to determine if we were invoked via xargs
.
I did get it working with ps
and grep
, but it seems like a hack and then a lot of work to have two ways to process the args. I could spend time on it, but @JamieMason let me know what you think.
To reiterate, if I’m the only one asking for this, feel free to close it.
That said, being piped from xargs
is expected behaviour from *nix CLI utilities.
To clarify, is the fix live or have you decided not to support it?
Hey @vitorgalvao, I decided not to proceed but if anyone has a nice solution they are welcome to get involved.
Doing
find … | imageoptim
works as expected, butfind … | xargs imageoptim
does not (it quits and shows the help message). This matters because if we want tofind … -print0 | xargs -0 imageoptim
, we can’t.