sharkdp / bat

A cat(1) clone with wings.
Apache License 2.0
48.83k stars 1.23k forks source link

Allow defining a filter/preprocessor #2289

Open xeruf opened 2 years ago

xeruf commented 2 years ago

i.e. a command that processes the input before it is displayed by bat.

I often want bat's nice filename display, ruler and line number, but can't give it the file directly. For example in #2024 I wanted to use cut, now I am building something with python -m json.tool to format json before displaying it in bat with syntax highlighting. By adding the ability to process the input, one could use both nicely :)

So rather than:

cat "$@" | python -m json.tool | bat --language json --style numbers

I could use something like:

bat --language json --style header,rule,numbers --process 'python -m json.tool' "$@"

This way I can distinguish the files.

I guess the processor should be invoked line-based, or there could be a separate --process-lines option.

keith-hall commented 2 years ago

the proof of concept of bat plugins would likely fit this use case: https://github.com/sharkdp/bat/pull/2203

xeruf commented 10 months ago

I just encountered a good use-case again, where I would like to reproduce git log -p in fossil, viewing each commit like a separate file in bat ^^