17

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

5 Answers 5

14

I found that in bash tput setf doesn't work. I found this commands for bash that are working well

handy tput commands

tput bold - Bold effect
tput rev - Display inverse colors
tput sgr0 - Reset everything
tput setaf {CODE}- Set foreground color, see color {CODE} below
tput setab {CODE}- Set background color, see color {CODE} below
Colors {code} code for tput command

Color {code}    Color
0    Black
1    Red
2    Green
3    Yellow
4    Blue
5    Magenta
6    Cyan
7    White
Sign up to request clarification or add additional context in comments.

1 Comment

tput is a great little tool with many other commands for controlling the terminal state and contents in shell scripting.
12

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.)

1 Comment

The below answers are good and neat, but this is the only one that works in Solaris xterm
5

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.

Comments

1

Installing and using colormake is another simple option.

 sudo apt-get install colormake

Comments

0

It seem more like you want the colorized output from make(1). In that case, I'd recommend patches for gnu make from http://git.goodpoint.de/?p=make.git;a=shortlog;h=refs/heads/color-v5.1 described on the ML: http://old.nabble.com/-rfc--Colorized-output-for-GNU-make--td32547742.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.