Colorizing the output of make

January 8, 2009

Submitted by: Taoufix

Category: Computers

905 views

Sometimes when compiling big projects using Makfiles, it can be hard to see the errors and warnings. To help with this task, colormake is a little script to colorize make’s output:

#!/bin/bash
#
# Usage: colormake [-w | -s PATTERN] MAKE_OPTIONS
#
#  -w           Yellow warnings
#  -s PATTERN   Make lines containing PATTERN green
 
# Colors
_ESC="$(echo -en '\e')"
C_NULL="${_ESC}[00;00m"
C_RED="${_ESC}[31;01m"
C_GREEN="${_ESC}[32;01m"
C_YELLOW="${_ESC}[33;01m"
C_LIGHTBLUE="${_ESC}[36;01m"
 
if [ "${1}" == "-s" ] && [ ! -z "${2}" ]; then
    pattern="${2}"
    shift 2
    exec make "$@" 2>&1 | sed \
	-e "s/\(^make.*\)/${C_LIGHTBLUE}\1${C_NULL}/" \
	-e "s/\(.* [Ee]rror:.*\)/${C_RED}\1${C_NULL}/" \
	-e "s/\(.*${pattern}.*\)/${C_GREEN}\1${C_NULL}/"
elif [ "${1}" == "-w"  ]; then
    shift
    exec make "$@" 2>&1 | sed \
	-e "s/\(^make.*\)/${C_LIGHTBLUE}\1${C_NULL}/" \
	-e "s/\(.* [Ee]rror:.*\)/${C_RED}\1${C_NULL}/" \
	-e "s/\(.* [Ww]arning:.*\)/${C_YELLOW}\1${C_NULL}/"
else 
    exec make "$@" 2>&1 | sed \
	-e "s/\(^make.*\)/${C_LIGHTBLUE}\1${C_NULL}/" \
	-e "s/\(.* [Ee]rror:.*\)/${C_RED}\1${C_NULL}/"
fi

And here is what it looks like:

colormake

If you liked this, please share it at your favorite sites:
  • Digg
  • Reddit
  • del.icio.us
  • Wikio
  • Facebook
  • Google
  • Technorati
  • TwitThis
  • MySpace
  • N4G
  • NewsVine
  • StumbleUpon
  • BlogMemes
  • Blogsvine
  • blogtercimlap
  • DotNetKicks
  • eKudos
  • Faves
  • Fleck
  • Scoopeo
  • Socialogs
  • Upnews
  • Yigg
  • E-mail this story to a friend!
  • Mixx

2 Responses :D Pretty Cool

Leave a Reply

:D :) :cry: :( 8O :twisted: :!: :vangry: :XO: :up: ;) :mrgreen: :halo: :kiss: :roll: :? 8) :evil: :oops: :| :?: :x :$: