The issue that solved my problem, is simply calling isatty
- through that I could know in advance if I have pending input or not.
Apparently I made people confused, that I was proposing 'it should be able to do Z because X and Y works':
echo files | imageviewer other-files
With semi-good reasoning in my opinion.
Suggesting to just not parse piped input is boring, as I am mainly the sole user of the program tbh, and I did want to sometimes pipe files into it, rather than doing imageviewer $(command)
.
Suggesting to use another program (xargs) to achieve also the same thing kinda works, but I find that a lame solution :D
So, I think I will adopt some sort of hybrid (which is ONLY possible because of the isatty
call)
if no files passed as arguments, check stdin
if files parsed, don't check stdin
optionally through a flag, enable both methods to work
Appreciate the insights on why it might be bad to just do random things.
---
P.S. yes I am playing with an image viewer, yes it does exist, it is here https://github.com/rphii/c-image-viewer -- probably a TON of things wrong with it. whatever, I'm not here to ramble on about how imperfect and ugly the code is, so yea look at it or not I don't care. just wanted to show that I am actually using the solution suggested.