Search:  
Gentoo Wiki

TIP_Colored_Command_Output_with_grc

This article is part of the Tips & Tricks series.
Terminals / Shells Network X Window System Portage System Filesystems Kernel Other

Contents

Introduction

Colored output with grc
Colored output with grc

grc is a Generic Colouriser which can be used for colorising the output of various commands such as diff, gcc, etc. The README file has a short description on how to write configuration files for additional programs.

Using grc

Shell: emerging grc
emerge -av grc


Add the following aliases to your shell initialization file:

File: ~/.zshrc
if [ "$TERM" != dumb ] && [ -x /usr/bin/grc ] ; then
  alias cl='/usr/bin/grc -es --colour=auto'
  alias configure='cl ./configure'
  alias diff='cl diff'
  alias make='cl make'
  alias gcc='cl gcc'
  alias g++='cl g++'
  alias as='cl as'
  alias gas='cl gas'
  alias ld='cl ld'
  alias netstat='cl netstat'
  alias ping='cl ping'
  alias traceroute='cl /usr/sbin/traceroute'
fi
Warning: normal make calls work normally, but the ncurses menu make menuconfig of the kernel sources does not like it.

people who know how to fix this, please share your knkowledge!

Colored emerge output

Warning: This can potentially cause some packages to fail to emerge, USE AT YOUR OWN RISK.

There is currently no clean way for colorising configure output (see Bug #139418) but building with make can be used with colors.

File: /etc/portage/bashrc
export MAKE="/usr/bin/grc -es /usr/bin/make"


Note: If you're experiencing problems on amd64, please try grc-1.0.8 or later.


Hacking Portage

You can hack portage to directly use grc. This enables you to view colored configure output (in most cases) and works with packages which like to use the MAKE variable in double quotes (e.g. app-cdr/cdrtools-2.01.01_alpha11-r1).

The following are the changes for portage-2.1.1. You can adapt those for your portage version, if the patch does not work for you.

File: portage-2.1.1-grc.patch
diff -Naur portage-2.1.1.orig/bin/ebuild.sh portage-2.1.1/bin/ebuild.sh
--- portage-2.1.1.orig/bin/ebuild.sh    2006-09-07 10:31:38.000000000 +0200
+++ portage-2.1.1/bin/ebuild.sh 2007-01-14 18:20:28.000000000 +0100
@@ -521,7 +521,7 @@
                        "$@" \
                        ${LOCAL_EXTRA_ECONF}

-               if ! ${CONFCACHE} ${CONFCACHE_ARG} ${TMP_CONFCACHE_DIR}         "${ECONF_SOURCE}/configure" \
+               if ! ${CONF_WRAPPER} ${CONFCACHE} ${CONFCACHE_ARG}              ${TMP_CONFCACHE_DIR} "${ECONF_SOURCE}/configure" \
                        --prefix=/usr \
                        --host=${CHOST} \
                        --mandir=/usr/share/man \
diff -Naur portage-2.1.1.orig/bin/emake portage-2.1.1/bin/emake
diff -Naur portage-2.1.1.orig/bin/emake portage-2.1.1/bin/emake
--- portage-2.1.1.orig/bin/emake        2006-08-01 19:43:13.000000000 +0200
+++ portage-2.1.1/bin/emake     2007-01-14 18:16:44.000000000 +0100
@@ -11,4 +11,4 @@
 #        /etc/make.globals here because emake is only called from an
 #        ebuild.

-exec ${MAKE:-make} ${MAKEOPTS} ${EXTRA_EMAKE} "$@"
+exec ${MAKEPRG:-make} ${MAKEOPTS} ${EXTRA_EMAKE} "$@"
File: portage-2.1.3-grc.patch [b33fc0d3]
--- ./portage-2.1.3/bin/emake.orig      2007-09-13 22:21:55.000000000 +0100
+++ ./portage-2.1.3/bin/emake   2007-09-13 22:22:14.000000000 +0100
@@ -11,4 +11,4 @@
 #        /etc/make.globals here because emake is only called from an
 #        ebuild.
 
-exec ${MAKE:-make} ${MAKEOPTS} ${EXTRA_EMAKE} "$@"
+exec ${MAKEPRG:-make} ${MAKEOPTS} ${EXTRA_EMAKE} "$@"
--- ./portage-2.1.3/bin/ebuild.sh.orig  2007-09-13 22:19:31.000000000 +0100
+++ ./portage-2.1.3/bin/ebuild.sh       2007-09-13 22:21:27.000000000 +0100
@@ -561,7 +561,7 @@
                        CONFCACHE=
                fi
 
-               vecho ${CONFCACHE} ${CONFCACHE_ARG} ${TMP_CONFCACHE_DIR} "${ECONF_SOURCE}/configure" \
+               vecho ${CONF_WRAPPER} ${CONFCACHE} ${CONFCACHE_ARG} ${TMP_CONFCACHE_DIR} "${ECONF_SOURCE}/configure" \
                        --prefix=/usr \
                        --host=${CHOST} \
                        --mandir=/usr/share/man \

You then only need to set those extra variables in your /etc/portage/bashrc.

File: /etc/portage/bashrc
export MAKEPRG="/usr/bin/grc -es /usr/bin/make"
export CONF_WRAPPER="/usr/bin/grc -es"

Colored system log

You can use grc to colorise your system log:

Shell: Color system log
grc tail /var/log/syslog

This can be used for printing out a colored syslog to your preferred tty.

Sysklogd

The author of grc gives some tips about colorising syslog output with sysklogd in the README file from gcr.

Quote: /usr/share/doc/grc-1.0.8/README.gz
Hint taken from logcoloriser README:

To have your syslog show on your tty12 in colour, do:
    mkfifo /dev/grc
    replace (or copy and edit) the /etc/syslog.conf line
    *.info;mail.*;authpriv.*;kern.*;local1.* |/dev/xconsole
    with :
    *.info;mail.*;authpriv.*;kern.*;local1.* |/dev/grc
    and add to your syslog startup script :
    grcat conf.log < /dev/grc >/dev/tty12 &

Well, simpler approach seems to be to use something like this
in your system startup script, if you have GNU tail:
    tail --follow=name /var/log/syslog | grcat conf.log >/dev/tty12 
or, if you have recent BSD tail:

    tail -F /var/log/syslog | grcat conf.log >/dev/tty12

Syslog-NG

This will print a colored system log on tty12.

File: /etc/syslog-ng/syslog-ng.conf
source src { unix-stream("/dev/log"); internal(); };
destination console_all { program("grcat conf.log > /dev/tty12"); };

# default log
log { source(src); destination(console_all); };


Resources

Retrieved from "http://www.gentoo-wiki.info/TIP_Colored_Command_Output_with_grc"

Last modified: Fri, 05 Sep 2008 23:20:00 +0000 Hits: 5,923