Not intuitive how to display colourized output with less on Fedora
scfc opened this issue · 4 comments
On Fedora and generally in the Linux environment, commands that can colourize their output typically have three options: On, off, and automatic where the colouration depends on whether standard output is connected to a TTY or not. With this experience, I tried to use xq
to inspect some XML file.
First try, xq file.xml
, send (beautifully) colourized output to my console, but exceeded the page size (due to the file's size).
So I fed xq
's output to less
(xq file.xml | less
), but this produced only non-colourized output.
With jq
, one can achieve colourized output in less
with jq -C . | less -R
, so I searched xq
's documentation for an option to colourize the output even if it is connected to a pipe, but found only --no-color
, the opposite of what I was trying to do.
Only after reading the source, I found that PAGER=less xq file.xml
does what I want. (On Fedora, $PAGER
is not set by default.)
So I'd like to propose a new option --color
à la ls
& Co. with three variants: --color=never
does not colourize the output, --color=always
colourizes the output unconditionally, and --color=auto
does so when standard output is connected to a TTY.
But such an option already exists:
curl -s https://www.w3schools.com/xml/note.xml | xq --color | less
Or am I missing something?
The help also describes it:
$ ./xq --help | grep color
-c, --color Force colorful output
--no-color Disable colorful output
Well, I missed the --color
option, so there is no need to add one. (Or, in other words: Thanks for having already added one :-).)
I tried to reconstruct why I did not see it, and it was due to me looking at the man page, not xq --help
's output. AFAICS, --color
is the only option not mentioned in the man page.
the only option not mentioned in the man page
Good catch, thank you! :)