Usage

colorecho [options] message
colorecho [options] < /path/to/file
echo "message" | colorecho [options]
colorecho -v
colorecho -s
colorecho -l
colorecho -h

Available Options

-s, --symbol-list

Shows symbol list that can to specify in foreground_color, background_color, text_attr.

-l, --index-list

Shows color index list that can to specify in foreground_color, background_color.

For example, When you would like to specify number 60, you must specify index60.

For example:
$ colorecho Hello -f index220 -b index90
Result:

screen shot

See color index list

-p, --pickup "pattern[,foreground_color[,background_color[,text_attribute]]]"

Decorates your specified pattern. You can use this option many times.

If you don’t specify foreground_color, will be used cyan as foreground_color for matches pattern. You have to escape with backslash, when your pattern is included comma, double quote, backslash etc.

-f,-b,t options will be used with the exception of string that matches pattern. -p option accept four arguments as below -p pattern,foreground,background,text_attribute. String that matches pattern will be decorated by -p option arguments. So version 3.0.0 and over can to specify decoration each -p option.

When pattern is surrounded by backslash like /pattern/, It will be work as regular expression.

For example:
$ echo "FooFoOfOO" | colorecho -p "/foo$/i,magenta" -p "/^foo/i,green"
Result:

screen shot

-H, --hightlight "foreground_color[,background_color[,text_attribute]]"

Highlight lines that match pattern which is specified by -p option.

A first of -p option correspond to a first of -H option, also a second of -p option correspond to a second of -H option. That’s why you can specify this options only same number as -p options.

If two and over patterns are matched in one line, -H option will be used that you specified at first. In case you specfied -H options more than -p options, surplus of -p option correspond to a first of -H option.

For example:
$ colorecho -e "xxxfooxxx\nxxxxxxfoo\nfooxxxxxx" -p "/foo$/,green" -H index85
Result:

screen shot

-f, --fg color_name

Specifies foreground color. You can see the list of value by colorecho -s and also colorecho -l.

-b, --bg color_name

Specifies background color. You can see the list of value by colorecho -s and also colorecho -l.

-t, --tx text_attribute[,...]

Specifies background color. You can see the list of value by colorecho -s. This option can to specify many values like that -t underline,bold,blink.

-w, --watch

Keeps wait for standard input. You can exit this mode follows keywords exit,quit,bye or Ctl + c.

For example:
$ tail -f /tmp/foo.log | colorecho -w -f gray -p foo.html,h_red,nil,bold,underline -H h_cyan
Result:

screen shot

--stripe

Decorates on every other line.

When you specified this option, -p option will be ignored. You can’t use --stripe option and -p option at the same time.

When you don’t specify any decoration by -f,-b,-toption, will be used cyan as value of -f option.

For example:
$ tail -f /tmp/foo.log | colorecho -w --stripe
Result:

screen shot

-r, --refresh-match

Tries to delete sequence code from input that matches -p option’s pattern.

-R, --refresh

Tries to delete sequence code from input. But It will works when you specified -f,-b,-t,-poptions.

For example:
$ tail -f /tmp/foo.log | colorecho -f index205 -w | colorecho -w --stripe -f index156 -R
Result:

screen shot

  • This example to add index205 color to the whole foreground, And then add index156 color to foreground on every other line. The whole foreground has already colored with index205, That’s why must to delete the sequence code before add index156 color on every other line.

-c file_name,...

Reads options from your specify file. You can specify many files as -c foo,bar,baz. If you have duplicated option name, a previous file be given priority over a subsequent file.

When you have ~/.colorecho/default or $COLORECHO/default, You souldn’t specify -c default because a default file will be read automatically.

More information is Check About option reading from file.

-n

Do not output the trailing newline.

-e

Enable interpretation of line feed.

-v

Shows version of color_echo.

-h, --help

Shows help message.

Example

You are looking for status code 4xx, 5xx. screen shot

Let’s turn color of 4xx yellow, turn color of 5xx red, and turn foreground color gray to be emphasized.

For example:
$ sed -n 1,1000p /var/log/httpd/access.log | colorecho -f gray -p "/\\s4..\\s/,h_yellow,nil,bold,underline" -H index156 -p "/\\s5..\\s/,h_red,nil,bold,underline" -H index197 | less -R
Result:

screen shot

Easy to find that now.

But options are rather long. So let’s move these to a file to call whenever you want.

~/.colorecho/status_code:
f=gray
p=/\s4..\s/,h_yellow,nil,bold,underline
H=index156
p=/\s5..\s/,h_red,nil,bold,underline
H=index197

When you specify options from file, shouldn’t escape \ or " to \\ or \" by backslash.

Let’s save that as ~/.colorecho/status_code, and then you can call that by -c status_code.
You can watch access log as the file grows by combination of tail, colorecho.

For example:
$ tail -f /var/log/httpd/access.log | colorecho -w -c status_code

You can use many kind of command with colorecho because colorecho can to receive standard input and also wait it.

combination example

vmstat's output will be added color like stripe :
$ vmstat -n 1 | colorecho -w --stripe
Highlights the specific port :
$ netstat -nat | colorecho -f gray -p :8080,red,nil,bold -H index52 -w
Highlights the specific user's process :
$ top | colorecho -p khotta,red,nil,bold,underline -H cyan -w
Highlights the specific pattern :
$ colorecho -p foo < foo.txt | less -R
Highlights the specific process :
$ ps aux | colorecho -p apache,red,nil,bold,underline -H cyan -w | less -R