bat icon indicating copy to clipboard operation
bat copied to clipboard

A `syntax-delimiter` option to reset the syntax highlighting state

Open chopper2000uk opened this issue 5 months ago • 2 comments

There may well be a better way to do this?

I wanted to pass my ZSH history through bat to give it some colour, but typos and misplaced quotes cause the syntax highlighting to follow through from one history item to the next. I could pass each entry though bat individually, but for many items that would impact performance.

If there was a --syntax-delimiter option you could control the bat syntax highlighting process to reset before each entry, so that styling from previous corrupt items don't flow through to the next items.

chopper2000uk avatar Jun 25 '26 15:06 chopper2000uk

Interesting idea, thanks for sharing. Generally if a static delimiter could be used, it should be trivial to add a custom syntax definition (.sublime-syntax file) to achieve the same thing without any Rust code changes needed. Perhaps you can share an example of such a history file, because my ~/.histfile for example contains no such delimiters - unless a newline not preceded by a backslash counts...

keith-hall avatar Jun 27 '26 14:06 keith-hall

Ah, hadn't thought about a custom syntax definition. Alternatively, better house keeping of my history!

With either of ZSH's setopt INC_APPEND_HISTORY or setopt SHARE_HISTORY, commands are appended immediately. So hitting Ctrl-c half way through a multi line command still appends it to the history.

Something like:

> setopt INC_APPEND_HISTORY
> my_func() {
# Ctrl-c
> setopt INC_APPEND_HISTORY
> echo "
# Ctrl-c

But did also wonder if there might be other use cases, maybe snippet files or concatenated files, where syntax issues could bleed through, affecting subsequent sections.

chopper2000uk avatar Jun 27 '26 15:06 chopper2000uk