Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If you do end up emitting color by default, please at least make it contingent on isatty() - maybe the user can override that but I rarely want it when redirecting.


As a counter-example, I hate that piping to less will generally strip colour unless I tell both less and the command to really output color.


It would be nice to be able to have something like 'colorless <command I want to pipe to less>', and the 'colorless' command will run the given program, fake a TTY so that the isatty() check passes and it outputs color, then pipe it into the pager.

Unfortunately, calling it colorless would be exactly the wrong name for it!


Check out lesstty from https://github.com/kilobyte/colorized-logs.

(Or https://github.com/jwilk/pagerboy, which supports pagers other than less.)


Thank you! That looks very useful.

The associated program 'ansi2txt' could also solve a similar problem for me from the other way round: I tend to have grep aliased to 'grep --color=always', simply because often I'm going to pipe the results to 'less' and I still want the colors. But this sometimes trips me up if I have a series of greps: The first grep output has color codes, making the followup greps fail. If grep could be made to strip out color codes prior to running, everything would work just as expected.

In general, if you're running a series of connected commands, it's only the last one that you want to get the colors from, with the special case exception of when the last command is 'less' - in which case, the next-to-last one should keep the colors. All ways that make this happen automatically are useful!


Considering less is more, wouldn't colorless be exactly the right name?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: