Skip to content

bat syntax support does not match vim #40

@arcnmx

Description

@arcnmx

Problem

I set up page as my git pager:

:; git config core.pager 'page -O -t git'
:; git diff
[ 0000000376 | WARN  | dump in page ]
cannot spawn bat, use stdout: Os { code: 2, kind: NotFound, message: "No such file or directory" }
diff --git ...

Though it worked, I was confused about the warning, not knowing what it was or that it was a dependency that needed to be installed.
After looking through the source, I tried installing it:

:; git diff
[bat error]: unknown syntax: 'git'

and now there's no output at all! One can't always assume that bat language names will match git filetypes.

Resolution

There appears to be no way to configure this behaviour. I could've set PAGE_LOG=error to silence all warnings, but there's no direct way to turn the bat fallback off. I also would be happy to run bat if the --language argument were omitted. I'd suggest:

  1. Some sort of argument/syntax that configures vim's filetype (-t) and bat's language (--bat-language? -T?) separately
  2. If -T defaults to -t's value, there should be a way to clear it with -T auto or something
  3. When a file path is provided instead of stdin, prefer bat --file-name argument instead of bat --language - this code seems incorrect, the extension is not a language and the filename should be passed instead if it is available.
    (bat uses the filename to auto-detect the language, but unlike --language, it will not panic if it does not recognize it)
  4. There should probably be a flag to explicitly turn bat on/off, perhaps -T none for example.
    So page -O -t pager -T auto would use bat, while page -O -t rust -T none would cat instead

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions