Sure, fine, okay, I'll read the darn man page for jq... okay it takes a "filter" and then some files. And the filter we want is.. . which, j

A terminal case of Linux

submited by
Style Pass
2021-09-25 19:00:07

Sure, fine, okay, I'll read the darn man page for jq... okay it takes a "filter" and then some files. And the filter we want is.. . which, just like files, means "the current thing":

There! Now you have pretty colors! But say your JSON file is actually quite large, and it doesn't fit in your terminal window, so you want to use a pager, maybe something like less.

AhAH! We can save colors to a file and print them later - and our friend xxd the hex dumper shows us that the colors are really part of the output.

So! ls knows its output is being redirected somewhere, and it doesn't print colors. Even when we execute it from a Rust program.

In ls.c, in the the decode_switches function, we can find a switch inside of a while(true) loop, that seems to process command-line arguments.

Initially, the value of out_tty is -1, but it persists across function calls (because it's static), so after the first call returns, it'll be 0 or 1, depending what isatty returns.

Leave a Comment