tags:

views:

123

answers:

2

Hi,

when compiling some projects on linux terminal, I get usually a long output consisting of a lot of information. Usually this information is MONOCHROME. I wonder if bash can be modified somehow, so in all outputs or in some specific outputs (like from Makefile, etc) I can get different colors dependeing on, for instance:

make[1]: Leaving directory 

or

g++ -DHAVE_CONFIG_H     -I. 

etc.

Thanks

+1  A: 

Sure, just use Bash functions, like, say this one:

make()
{
  pathpat="(/[^/]*)+:[0-9]+"
  ccred=$(echo -e "\033[0;31m")
  ccyellow=$(echo -e "\033[0;33m")
  ccend=$(echo -e "\033[0m")
  /usr/bin/make "$@" 2>&1 | sed -E -e "/[Ee]rror[: ]/ s%$pathpat%$ccred&$ccend%g" -e "/[Ww]arning[: ]/ s%$pathpat%$ccyellow&$ccend%g"
  return ${PIPESTATUS[0]}
}

(Originally via Highlight Warnings in Make.)

Jeff Walden
+1  A: 

You can do this portably by using the tput command and the terminfo(5) database. For example,

tput setf 5

with terminal as standard out, will set the foreground color to purple (or something like it; I'm color blind). tput setf 0 resets the foreground color to the default.

For more information, look up terminfo.

Norman Ramsey
very funny :-P thanks a lot
Werner