Pygments Dig Lexer
Find a file
2023-01-19 09:22:21 +01:00
.gitignore Initial commit 2020-11-22 08:00:28 +01:00
dig-lexer.py feat: highlight ip6.arpa question with separation at upper-half hextet boundaries 2023-01-19 09:22:21 +01:00
LICENSE Add license 2020-11-23 02:22:27 +01:00
README.md Change example in README to only pygmentize when on a TTY 2020-11-23 20:52:38 +01:00
screenshot.png Update screenshot 2020-11-23 01:47:54 +01:00

Pygments lexer for dig output

This is work in progress and probably quite horrible.

What?

This is a lexer for Pygments that can lex the output of BIND 9's dig command to provide colorful syntax highlighting for dig:

Screenshot of colorful dig output

Why?

dig output can be hard to read, especially with +trace. Having some colors in the output helps a lot when reading large dig responses.

How to use?

Put something like this in your shell's config, e.g. .bashrc, .zshrc, or whatever your shell uses:

function dig() {
    if [[ -t 1 || "$DIG_COLOR" == "always" ]]; then
        /usr/bin/dig $@ | pygmentize -F tokenmerge -xl path/to/dig-lexer.py -Ostyle=monokai
    else
        /usr/bin/dig $@
    fi
}

Then rehash your shell config or start a new session. Now calling dig will call this function instead, passing the arguments to the original dig command, e.g. in /usr/bin/dig, and pipe the output through pygmentize.

If necessary, you can still call the original dig by its full path, e.g. /usr/bin/dig instead of just dig.