How I print my text documents with fancy colours | Hund

Hund

How I print my text documents with fancy colours

Saturday, February 13, 2021

I often read my plain text documents using cat. For the most part that works just fine, but for some larger documents—especially documents with documentation that contains a lot of headers, lists and folds—it can be somewhat difficult to read the document.

That’s why I’m using Supercat for things like this. It works just like cat (hence the name), but it also supports colours using regular expressions.

A compact demo with a Markdown document.

The markers “{{{” and “}}}” are Neovim folds. I can’t imagine living without folds. I use them all the time, even though they do make the file ‘cluttery’ to read with any other standard tool.

It should be noted that this works with a pager as well. If the document is really large, I will page it to less.

Supercat works by specifying a configuration file and the file you want to print:

$ spc -c ~/.config/supercat/markdown.conf demo.md

My configuration file for my Markdown documents looks like this:

# spc configuration file
#
# col - color (blk, red, grn, yel, blu, mag, cya, whi)
#
#   a - color attribute (console_code)
#         ' ':normal          (0)
#         '-':normal          (0)
#         'b':bold            (1)
#         'u':underline       (4)
#         'r':reverse-video   (7)
#         'k':blink           (5)
#
#   n - number of matches,  (' ':1, '1'-'9':1-9, '0':all)
#
#   t - pattern type
#         'c':chars     (strchr)
#         's':string    (strstr)
#         't':regexp    (regcomp) (convert 10-digit unix time to MMDDHHMMSS)
#         'r':regexp    (regcomp)
#         ' ':regexp    (regcomp)
#
#                    col a n t pattern
#################### ### # # # ########################################
H1                   red   1   (^#\s.*$)
H2                   yel   1   (^##\s.*$)
H3                   yel   1   (^###\s.*$)
H4                   yel   1   (^####\s.*$)
Header               red   1   (^---.*$)
Fold                 blk   1   (# \}\}\})
Fold                 blk   1   (\}\}\})
Fold                 blk   1   (\{\{\{)
List                 blu   1   (^\s*\*)

It only supports headers, lists and folds, which is all that I use for formatting my plaintext documents.