GRC
GRC, or the "Generic Colouriser" is a utility that lets you run output through a script that adds colour via regular expressions. This doesn't sound too useful, but once you use it you'll never look back. The easiest way to show you is to add an example. Let's start with ping
- here's a screenshot without GRC.
Here's one with GRC:
The different is subtle, but it makes all the difference. It helps you see the information that you're looking for more easily. There's loads of built in stylesheets, including things like diff
and make
.
We start off by creating an alias for grc. We use -es
to make sure that error output is parsed too, then written back to stdout.
bash
alias colourify="grc -es --colour=auto"
Then, we want to make sure that all of the commands that we support are run via our new alias. Here's what I have set up:
bash
alias colourify="grc -es --colour=auto"alias configure='colourify ./configure'alias diff='colourify diff'alias make='colourify make'alias gcc='colourify gcc'alias g++='colourify g++'alias netstat='colourify netstat'alias ping='colourify ping'alias traceroute='colourify traceroute'
By default, grc comes with a set of commands that it supports out of the box. You can see the regular expressions that it matches by running:
bash
$ cat /etc/grc.conf
As well as this, I set up a few of my own regular expressions (e.g. for cURL highlighting). To do this, I add the following to ~/.grc/grc.conf
.
bash
# curl command(^|[/\w\.]+/)curl\s?conf.curl
See how it specifies conf.curl
? This is the highlighting configuration file that it will use. Let's go ahead and create that at ~/.grc/conf.curl
.
bash
# HTTP headerregexp=^([A-Z].*)\:\s(.*)$colours=default, default, cyancount=more=====# HTTP successregexp=^HTTP.*?\s([1-3]\d{2}.*)$colours=default, greencount=more=====# HTTP errorregexp=^HTTP.*?\s([4|5]\d{2}.*)$colours=default, redcount=more=====# JSON attributeregexp=(\".*\")\:colours=default, bluecount=more=====# String valueregexp=\:\s(\".*\"),?$colours=default, yellow, defaultcount=more=====# Number valueregexp=\:\s(\d+),?$colours=default, magenta, defaultcount=more=====# Boolean valueregexp=\:\s(true|false),?$colours=default, bold greencount=more=====# Null valueregexp=\:\s(null),?$colours=default, bold redcount=more
Finally, we need to add an alias for curl
bash
alias curl='colourify curl'
Then give it a go:
This is just the start - you can use grc to add colour to any terminal output you can think of. All you need is regular expressions and a bit of time