Supercat Text Colorizer

The application Supercat colors any input text based on the type of file and a set of rules associated with the file type. The rules are used to match strings found in the input text and can be specified using simple characters or strings, regular expressions and special time-formatting rules. Supercat is flexible and extensible; new file types can be added without software development.

You can download Supercat (at the time of writing the latest version was 0.5.3) at https://supercat.nosredna.net. Supercat is also available in Gentoo's portage system and Ubuntu's to-be-released Hardy Heron. Installing Supercat is fairly straightforward -- the only thing you need to specify is the --system-directory 'configure' option. Once installed, you can run Supercat on numerous files. For example:

$> spc file.c

This presents you with a colorized listing (similar to how Vim colors text). Supercat tries to figure out the file type based on the file suffix or, in the case of files with the extension .log, Supercat removes the suffix and looks up the file name (e.g., error.log is file type error). The user can explicitly override the file type on the command line.

All rules for colorizing text are stored in files with names of the form spcrc-ext, where "ext" is the file type. These files are stored in the configured "system directory" or else your private ~/.spcrc directory.

All rules for colorizing text are stored in files with names of the form spcrc-ext, where "ext" is the file type. These files are stored in the configured "system directory" or else your private ~/.spcrc directory. For example, the rules for a C source code file in spcrc-c might look like:

# HTML COL COL A N T CHARACTER, STRING or REGULAR EXPRESSION

########## ### # # #
#####################################################
Red        red b
    ([a-zA-Z][a-zA-Z0-9_]*)[[:space:]]*(
Yellow     yel b    
(while|for|if|switch|main|return)[[:space:]]*(
Yellow     yel b   s
else
Cyan       cya     s case
Cyan       cya     s return
Cyan       cya     s default
Cyan       cya b    
[[:space:]]*(include)
Green      grn       (do)[[:space:]]*{
Green      grn       (break|continue)[[:space:]]*;
Magenta    mag   
   (int|char|short|float|double|long|unsigned)[[:space:]]
Blue      
blu b     [^[:alnum:]_]([[:digit:]]+)
Yellow     yel      
"(.*)"
Yellow     yel       
Magenta    mag
    c :;

Matching is performed using the information in the pattern at the end of each line in the configuration file. If a portion of a line matches the pattern then the matching characters are given the specified color. The type of matching is specified in the 'T' column and defaults to REGEXP.

The other columns specify the video coloring attributes to the used. "COL" indicates the console color; "A" is an optional video attributes (e.g., bold, underline); "N" governs the number of times a match is applied to a line. The "HTML COL" column is there because Supercat supports outputting its colorized text in HTML format for viewing with a Web browser.

Supercat provides flexibility and extensibility without requiring programming. There are numerous other options and goodies that Supercat has to offer, but I'll let you find them as they are extensive and out of the scope of this short HOWTO.

This Tech Tip was brought to us by Thomas in New Jersey, USA. Thanks, Thomas!

Instant fame is easy at Linux Journal. Just send us your useful Tech Tips to share with the Linux Community, and we'll send you a cool t-shirt for your efforts!

Please note: Tech Tips featured in this specific section of LinuxJournal.com are kindly brought to us by readers and are not necessarily tested by LinuxJournal.com editors.