• Stars
    star
    136
  • Rank 267,670 (Top 6 %)
  • Language
    JavaScript
  • License
    Other
  • Created over 12 years ago
  • Updated about 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Mirror of Radovan Garabík's - Generic Colourizer for terminal apps
===================================================================
                  Generic Colouriser

Radovan Garabík  http://kassiopeia.juls.savba.sk/~garabik/software/grc.html
garabik @ kassiopeia.juls.savba.sk

===================================================================

Being overflooded with different logfile colo(u)?ri(s|z)ers, colortails,
gccolors, colormakes and similar programs for making  text files or outputs
of different programs more readable by inserting ansi colour control codes
into them, I decided to write  my very own colouriser, eventually providing
the functions of all those others.

Two programs are provided: grc and grcat.  The main is grcat, which acts as
a filter, i.e. taking standard input, colourising it and writing to
standard output.

grcat takes as a parameter the name of configuration file.

Directories  ~/.grc/, /usr/local/share/grc/, /usr/share/grc/ are searched
for the file (in this order). If the file is not found, it is assumed to be
an absolute path of a configuration file located elsewhere.

Configuration file consists of entries, one per regexp, entries are 
    separated with lines with first character non-alphanumeric (except #).
    Lines beginning with # or empty lines are ignored.

    Each entry consists of several lines.
    Each line has form:
        keyword=value
        where keyword is one of: regexp, colours, command, skip, count
        Only regexp is mandatory, but it does not have much sense by itself
        unless you specify at least a colour, skip or command keyword as well.

        regexp is the regular expression to match

        colours is the list of colours, separated by commas (you can specify only 
        one colour), each colour per one regexp group specified in regexp.
        if you use special colour name "previous", colour of the previous line
        of text will be used (actually, if both the first and last character of 
        the previous line are of different colour than the default one,
        colour of the first one will be used).
        Another special colour name "unchanged" will leave the colour 
        unchanged, useful if you need some context for matching 
        regular expression and you want to leave the colour of context
        unchanged.
        Yet another special name is an arbitrary string enclosed in 
        straight quotes. This string will be inserted directly into
        the output in front of the matching expression. The string will
        be eval'ed, so you can use usual python escape sequences.
        This is useful on a 256-colour enabled xterm, where e.g.
         colours="\033[38;5;22m" will give you a dark green (inspired
        by Rutger Ovidius). Caveat: the string cannot contain a comma. This
        is due to my laziness :-)


        command is command to be executed when regexp matches. Its output will
        be mixed with normal stdout, use redirectors ( >/dev/null) if you want
        to suppress it.
        
        skip can be skip=yes, if that case the matched line is skipped
        (discarded from the output), or skip=no, when it is not skipped.
        Default (if you do not have skip keyword) is of course not skipped.

        count is one of words: once, more, stop, previous, block or unblock

            once means that if the regexp is matched, its first occurrence is coloured
            and the program will continue with other regexp's.

            more means that if there are multiple matches of the regexp in one line,
            all of them will be coloured.

            stop means that the regexp will be coloured and program will move to the
            next line (i.e. ignoring other regexp's) 
            
            previous means the count will be the same as for the previous line
            
            block marks a start of a multiline block of text, coloured with
            the same colour
            
            unblock, obviously, marks the end of such a block



        example:

        # this is probably a pathname
        regexp=/[\w/\.]+
        colour=green
        count=more

        this will match /usr/bin, /usr/local/bin/, /etc/init.d/syslogd and similar
        strings and paint it with green.

        Another example:

        regexp=^-{1,2}\s{0,1}$
        colours=red
        count=block
        -
        regexp=^\s{0,5}$
        colours=default
        count=unblock
    
        this will turn all correctly formatted mail signatures red.

    Regular expressions are evaluated from top to bottom, this allows nested
    and overlapped expressions. (e.g. you colour everything inside parentheses
    with one colour, and if a following expression matches the text inside 
    parentheses, it will be also coloured)

Typical usage:

grcat conf.log < /var/log/syslog
/usr/sbin/traceroute www.linux.org | grcat conf.traceroute
grcat conf.esperanto < Fundamento.txt  | less -r

To facilitate the use, command grc acts as frontend for grcat, automatically 
choosing the configuration files, so you can write:

grc netstat
grc ping hostname
grc tail /var/log/syslog

etc...

    grc will execute command command with optional parameters piping its stdout
    into grcat.

    Configuration file for grcat is determined by /etc/grc.conf or 
    ~/.grc/grc.conf file.

    Format of /etc/grc.conf or ~/.grc/grc.conf: each entry consists of 2 lines,
        between entries there can be any number of empty lines or lines beginning
        with # (comments)

        First line is regular expression, second line the name of configuration
        file for grcat.

        Configuration file after the first regular expression matching the rest of
        line after grc will be passed to grcat as its configuration file

        For example, if you have 

        # log file
        \b\w+\b.*log\b
        conf.log

        # traceroute command
        (^|[/\w\.]+/)traceroute\s
        conf.traceroute

        in your /etc/grc.conf, then typing grc cat /var/log/syslog will use 
        conf.log to colourise the output,
        grc /usr/sbin/traceroute www.linux.org will use conf.traceroute
    
Miscellaneous remarks:

    You should get yourself familiar with regular expressions. Good reading is 
    at http://docs.python.org/dev/howto/regex.html

    The program is not yet optimized for speed. There are places that can 
    give a big boost if optimized.

    Regular expressions are handled by python, it means that they may be
    slightly different from those you know from perl or grep. It's not my 
    fault in that case.

    Colours are one of: 
        none, default, bold, underline, blink, reverse, concealed, 
        black, green, yellow, blue, magenta, cyan, white,
        on_black, on_green, on_yellow, on_blue, on_magenta, on_cyan, on_white
        beep
    on_red means that the background (instead of foreground) is painted 
    with red etc...

    Additional colours can be: dark, italic, rapidblink, strikethrough.
    These are supported only on some terminals, so if you want to write
    portable configuration files, avoid uing them (idea by James Rowe).

    there can be more attributes per line (separated by space), e.g.

    # this is probably a pathname
    regexp=/[\w/\.]+
    colours=bold blink green
    count=more

    will display pathnames in bold blinking green



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
    

More Repositories

1

flint

Check your project for common sources of contributor friction.
Go
1,130
star
2

dotfiles

$HOME sweet ~/
Shell
378
star
3

rdio-cli

CLI for Rdio on Mac
Ruby
101
star
4

fumblr

Stop fumbling with your Tumblr theme development - mashup of my own process with Thimblr
Ruby
98
star
5

compass-wordpress

Compass plugin for creating WordPress themes using Sass
Ruby
89
star
6

compass_formalize

Compass and Sass port of Nathan Smith's Formalize project
JavaScript
84
star
7

octonaut

Simple CLI for GitHub
Ruby
70
star
8

chargify

Ruby wrapper for the chargify.com SAAS and billing API
Ruby
61
star
9

gowalla

Ruby wrapper for the Gowalla API.
Ruby
57
star
10

sass-and-compass-in-action

Code samples for Sass and Compass in Action
CSS
50
star
11

topsy

Ruby wrapper for the Topsy.com Otter API
Ruby
33
star
12

pingwynn

Questions, feedback, suggestions, etc. 🐧
28
star
13

presto

Padrino + NestaCMS
Ruby
26
star
14

athena-cli

CLI for Amazon Athena, powered by JRuby
Ruby
24
star
15

groupon

Ruby wrapper for the Groupon API
Ruby
20
star
16

transparency-data

Wrapper for the Sunlight Transparency Data API
Ruby
19
star
17

chunky-baconfile

Tasty wrapper for the Baconfile API
Ruby
14
star
18

plancast

Wrapper for the unpublished Plancast API
Ruby
13
star
19

ujs_sort_helper

Unobtrusive sort helper for Rails
JavaScript
12
star
20

readernaut

Ruby wrapper for the Readernaut social reading site API
Ruby
11
star
21

formstack

Ruby wrapper for the Formstack API
Ruby
9
star
22

dallasrb-shell

Ruby
7
star
23

buzzsprout

Ruby wrapper for the ghost Buzzsprout API
Ruby
6
star
24

nesta-plugin-sluggable

Sluggable posts for Nesta CMS
Ruby
6
star
25

authentic_jobs

Find your next gig from the console. Ruby wrapper for the Authentic Jobs API
Ruby
5
star
26

nesta-plugin-linkable

Easy link posts for Nesta CMS
Ruby
5
star
27

backtweets_helper

Rails helper for Backtweets widgets
Ruby
5
star
28

thor-tasks

Utility thor scripts
Ruby
4
star
29

nextstop

Ruby wrapper for the Nextstop.com API
Ruby
4
star
30

giact

Ruby wrapper for the Giact POST API
Ruby
3
star
31

textmate-themes

My TextMate themes
3
star
32

titanium-toolbox

WIP Ti boilerplate across several projects
3
star
33

octokit-sandbox

Play area for experimenting with Octokit
2
star
34

pengwynn.github.com

HTML
2
star
35

nesta-plugin-project-meta

Plugin for Nesta CMS to show Github, Rubygems data for projects
Ruby
2
star
36

an-test

1
star
37

bleikamp.github.com

Personal site of Internet celebrity Ben Bleikamp
1
star
38

ti-vim-snippet

`ti` snippets for writing `coffescript` and `sass`
1
star