commit 1a8c98618dcc8393027bc1309f15c6e708643de1 Author: s3lph Date: Sun Nov 22 08:00:28 2020 +0100 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8c33f7d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.pyc +**/__pycache__/ \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..093d2a9 --- /dev/null +++ b/README.md @@ -0,0 +1,25 @@ +# Pygments lexer for `dig` output + +This is **work in progress** and probably quite horrible. + +## What? + +![Screenshot of colorful dig output][screenshot] + +## Why? + +`dig` output can be hard to read, especially with `+trace`. + +## How to use? + +Put something like this in your .bashrc, .zshrc, or whatever: + +```bash +function dig() { + /usr/bin/dig $@ | pygmentize -xl path/to/dig-lexer.py -Ostyle=monokai +} +``` + +Then rehash your shell config. + +[screenshot]: https://gitlab.com/s3lph/dig-lexer/-/raw/master/screenshot.png \ No newline at end of file diff --git a/dig-lexer.py b/dig-lexer.py new file mode 100644 index 0000000..57e553d --- /dev/null +++ b/dig-lexer.py @@ -0,0 +1,28 @@ +from pygments.lexer import ExtendedRegexLexer +from pygments.token import * + +class CustomLexer(ExtendedRegexLexer): + name = 'Dig' + aliases = ['dig'] + filenames = ['*.zone'] + + def parse_record(lexer, match, ctx): + yield match.start('zone'), Name.Function, match.group('zone') + if match.group('ttl'): + yield match.start('ttl'), Number.Integer, match.group('ttl') + yield match.start('cls'), Name.Class, match.group('cls') + yield match.start('typ'), Name.Tag, match.group('typ') + yield match.start('value'), String.Escape, match.group('value') + if match.group('extval'): + yield match.start('extval'), String.Double, match.group('extval') + yield match.start('comment'), Comment.Special, match.group('comment') + ctx.pos = match.end() + + tokens = { + 'root': [ + (r'; <<>>.*\n', Comment.Hashbang), # dig header + (r';;.*', Generic.Subheading), # comment section headers + (r';.*', Comment.Single), # comment section headers + (r'(?P(.*)?\.\s+)(?P[0-9]+\s+)?(?P[A-Z0-9]+\s+)(?P[A-Z0-9]+\s+)(?P.+?)(?P\s+?\(\s*?(\n.*?(;[^\n]*)?)+?\))?(?P(\s+?;.*)?\n)', parse_record), + ] + } diff --git a/screenshot.png b/screenshot.png new file mode 100644 index 0000000..d00ba99 Binary files /dev/null and b/screenshot.png differ