by arfar · 11y ago · 0 comments
'ls' is a bag of weird (bad?) UX. When first starting on the command line, I could never figure out how grepping the output of ls actually worked. Then I think I looked at some of the code, or someone told me, that when ls outputs, it checks to see where the data is going, if it's STDOUT then it pretty prints columns (and probably other things), otherwise it just the more sane 1 line per item.
There are two cases when you should definitely take advantage of isatty:
1) Your tool, by default, outputs in color.
2) Your tool, by default, outputs progress, which you keep on a single line by overwriting by outputting \r.
Both of these potentially annoying when your command is used in a script, and especially annoying if they are called from cron.
In other cases I agree with you, getting too creative violates the principle of least surprise.
Although some of these tools can be persuaded to stop including escape sequences with the right switch, the right switch varies with the tool, and learning the right switch to use with a particular tool requires reading a large fraction of a very long man page. In contrast, 20 years ago, IIRC all command-line tools I used respected TERM=dumb.
Since isatty() was mentioned, let me point out that directing the output of the tools named above to a named pipe instead of a pseudo-TTY is not enough to get them to stop sending terminal escape sequences.
If I wanted that behavior, I would have typed 'ls -1' also.
Often times when I am running ps that's exactly the information I want to see.
I guess you could argue ef's length as an advantage but if you're on a 1080 screen, meh.
I use 'w' command if I want CPU info.