rainbow
rainbow copied to clipboard
Allow forced colorization via an option
Log files are usually viewed on the console using tools like less.
Similar to rainbow, grep omits colors from its output if the destination is not console. However, it allows forcing it using --color=always
. This combined with the -R
switch in less allows viewing the output with colors and have the scroll, search options of less.
At the moment rainbow seems to want to dump the entire file to console. Unless this is mentioned in the documentation somewhere, and I've missed it.
@Kshitiz-Sharma: I agree, a --color[=WHEN]
flag (never
, always
, default auto
) would be great.
As a workaround, you can use the undocumented environment variables RAINBOW_ENABLE_STDOUT
/RAINBOW_ENABLE_STDERR
. Below using hexdump
to verify the byte output instead of screenshots with color. Replace hexdump -c
with cat
to get the "real" colorized output.
With pipe from rainbow
, piped to hexdump
.
Note that the b
would colored red without hexdump
.
RAINBOW_ENABLE_STDOUT=true rainbow --red 'b' echo 'abc' | hexdump -c
0000000 a 033 [ 3 1 m b 033 [ 3 9 m c \n 033 [
0000010 0 m
0000012
With pipe through rainbow
, piped to hexdump
.
echo 'abc' | RAINBOW_ENABLE_STDOUT=true rainbow --red 'b' | hexdump -c
Note that the b
would colored red without hexdump
.
0000000 a 033 [ 3 1 m b 033 [ 3 9 m c \n 033 [
0000010 0 m
0000012
Watching a command, with output piped to rainbow
My use-case is watch --color
. Note that --color
is not available in all watch
versions, but at least in the apt
package procps
from procps-ng
v3.3.15.
Colorization works only with RAINBOW_ENABLE_STDOUT=true
. Note that the output would be garbled without --color
.
watch --color "echo 'abc' | RAINBOW_ENABLE_STDOUT=true rainbow --red 'b'"