pygments-dig-lexer/README.md

36 lines
1.3 KiB
Markdown
Raw Normal View History

2020-11-22 08:00:28 +01:00
# Pygments lexer for `dig` output
This is **work in progress** and probably quite horrible.
## What?
2020-11-23 02:17:56 +01:00
This is a [lexer][lexer] for [Pygments][pygments] that can lex the output of [BIND 9's `dig` command][dig] to provide colorful syntax highlighting for `dig`:
2020-11-22 08:00:28 +01:00
![Screenshot of colorful dig output][screenshot]
## Why?
2020-11-23 02:17:56 +01:00
`dig` output can be hard to read, especially with `+trace`. Having some colors in the output helps a lot when reading large dig responses.
2020-11-22 08:00:28 +01:00
## How to use?
2020-11-23 02:17:56 +01:00
Put something like this in your shell's config, e.g. `.bashrc`, `.zshrc`, or whatever your shell uses:
2020-11-22 08:00:28 +01:00
```bash
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
2020-11-22 08:00:28 +01:00
}
```
2020-11-23 02:17:56 +01:00
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`.
2020-11-22 08:00:28 +01:00
2020-11-23 02:17:56 +01:00
[screenshot]: https://gitlab.com/s3lph/pygments-dig-lexer/-/raw/master/screenshot.png
[lexer]: https://en.wikipedia.org/wiki/Lexical_analysis
[pygments]: https://pygments.org/
[dig]: https://en.wikipedia.org/wiki/Dig_(command)