bat icon indicating copy to clipboard operation
bat copied to clipboard

support vi ft comments

Open xenoterracide opened this issue 4 years ago • 6 comments

Sadly, not all file types encode their file type as an extension. Even worse, a lot of files use meaningless extensions where you have to look at their directory. For example, systemd uses environment.d/*.conf for .env files, that could also be parsed as .sh because they also allow for simple interpolation.

Would be cool to support the vi way for being able to use a comment to define it. Suggesting specifically this because many files may already have it, and/or it serves another purpose.

https://unix.stackexchange.com/a/19869/29

e.g.

# vi: ft=gitconfig

xenoterracide avatar Aug 16 '21 17:08 xenoterracide

This has been requested a few times. Please see #1732, for example.

Even worse, a lot of files use meaningless extensions where you have to look at their directory. For example, systemd uses environment.d/*.conf for .env files, that could also be parsed as .sh because they also allow for simple interpolation.

You can actually tell bat to map paths like this to a specific syntax. For your example, you would have to add something like

--map-syntax '**/environment.d/*.conf:Bourne Again Shell (bash)'

to bats config file.

sharkdp avatar Aug 16 '21 17:08 sharkdp

bat actually highlights these systemd files with the INI syntax currently (see https://github.com/sharkdp/bat/pull/1060). Let us know if you think this can be improved.

sharkdp avatar Aug 16 '21 18:08 sharkdp

Screenshot from 2021-08-16 17-58-12 looks pretty flat on my system, ;) and they're closer to sh than INI, afaik. Obviously the're an example. I've seen some .conf files recently that I'm not even sure what they are...

xenoterracide avatar Aug 16 '21 22:08 xenoterracide

--map-syntax '**/environment.d/*.conf:Bourne Again Shell (bash)'

Could we shorten this to --map-syntax '**/environment.d/*.conf:bash' ?

SuperSandro2000 avatar Aug 21 '21 12:08 SuperSandro2000

Duplicate of #160

... which is closed. It maybe should be reopened.

Either way, this is a duplicate of that one.

Enselic avatar Dec 05 '21 18:12 Enselic

Duplicate of #160

Enselic avatar Dec 05 '21 18:12 Enselic