Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What color options exist for ack(-grep) for colorization of output, logs, etc?

Where can one find a listing of all color combinations or such available to use with ack(-grep)? I find that passing logs through ack-grep can be quite helpful at detecting errors, warnings or various other conditions especially with colorization, however I haven't found an authoritative list of what combos may be used, etc.

tail -f development.log \
| ack-grep --flush --passthru --color --color-match=yellow "^.*warning.*"

I've seen options such as the standard colors: red, blue, yellow, green, etc.

And I've seen that you can use "white on_green"

But what else?

like image 764
ylluminate Avatar asked Mar 08 '12 21:03

ylluminate


People also ask

How do you color grep output?

So grep comes with --color='auto' option. It surrounds the matching string with the colour, thus resulting in enhanced output. Now you know grep can color-highlighting the matched text or words in its output. However, by default, that option is turned off.


2 Answers

ack uses Perl's Term::ANSIColor module, so you can check what is available to you with:

perldoc Term::ANSIColor

Here's the relevant excerpt.

   The recognized normal foreground color attributes (colors 0 to 7) are:

     black  red  green  yellow  blue  magenta  cyan  white

   The corresponding bright foreground color attributes (colors 8 to 15)
   are:

     bright_black  bright_red      bright_green  bright_yellow
     bright_blue   bright_magenta  bright_cyan   bright_white

   The recognized normal background color attributes (colors 0 to 7) are:

     on_black  on_red      on_green  on_yellow
     on_blue   on_magenta  on_cyan   on_white

   The recognized bright background color attributes (colors 8 to 15) are:

     on_bright_black  on_bright_red      on_bright_green  on_bright_yellow
     on_bright_blue   on_bright_magenta  on_bright_cyan   on_bright_white

   For any of the above listed attributes, case is not significant.

I'm glad to see you using --passthru, too.

We'd welcome you on the ack-users mailing list

like image 99
Andy Lester Avatar answered Sep 27 '22 22:09

Andy Lester


Another interesting thing to do is to create a ~/.ackrc with default configuration like:

--color
--color-match=on_white
--color-filename=red
--color-lineno=magenta

To get readable results on white console background for instance. (Actually the reason why I started to search and found this question and the helpful reply from @andy-lester).

like image 30
Ondrej Burkert Avatar answered Sep 27 '22 21:09

Ondrej Burkert