For example, I\'d like to color the output of the locate
command so it\'s easily distinguished from the other terminal text.
It should work something li
I think the hl command available on git hub might help you :
have a look at http://www.flashnux.com/notes/page_000022_US.html
As suggested by Jonathan Leffler, comment posted as an anwser:
grep --color
will provide colour
I prefer use highlight utility:
highlight -O xterm256 -S sh
-S sh
here means treats the input as shell script syntax.
More info: http://www.andre-simon.de/
I set it as an alias through ~/.bashrc:
There is a far better way to achieve customizable coloring:
colorit
You can use it as shown in other answers via some_command | colorit
but it is nicely configurable over the .coloritrc
. In mine I have stuff like
dnl Define some useful color variables
define(`red', `1')
define(`green', `2')
define(`magenta', `5')
dnl
dnl Mark macro arguments: regexp foreground-color [background-color]
dnl
define(`mark', ``mark "$1"'' `ifelse(`$#', `3', ``"\033[3$2;4$3m"'',
``"\033[3$2m"'')' `"\033[m"')
dnl
divert
mark(`warning', magenta)
mark(`Warning', magenta)
mark(`Traceback', magenta)
mark(`Error', red)
mark(`FAIL', red)
mark(`ERROR', red)
mark(`XFAIL', green)
mark(`ok', green)
mark(`OK', green)
mark(`PASS', green)
and use it all the time for coloring compiler output and similar stuff. See my .coloritrc for more.