Initial commit
This commit is contained in:
commit
1a8c98618d
4 changed files with 55 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
*.pyc
|
||||||
|
**/__pycache__/
|
25
README.md
Normal file
25
README.md
Normal file
|
@ -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
|
28
dig-lexer.py
Normal file
28
dig-lexer.py
Normal file
|
@ -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<zone>(.*)?\.\s+)(?P<ttl>[0-9]+\s+)?(?P<cls>[A-Z0-9]+\s+)(?P<typ>[A-Z0-9]+\s+)(?P<value>.+?)(?P<extval>\s+?\(\s*?(\n.*?(;[^\n]*)?)+?\))?(?P<comment>(\s+?;.*)?\n)', parse_record),
|
||||||
|
]
|
||||||
|
}
|
BIN
screenshot.png
Normal file
BIN
screenshot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 88 KiB |
Loading…
Reference in a new issue