Open hugomg opened 2 years ago
The file(1)
command does detect Fish scripts, but deliberately gives them the same MIME type as any other shell script:
Meanwhile, Kakoune's fish filetype plugin only checks for filenames ending in .fish
:
It looks like file(1)
doesn't try to distinguish between shell syntaxes (Bourne-style shells all get text/x-shellscript
but so does tcsh
), so maybe the fish filetype plugin should add a filetype=sh
hook that checks the first line of the buffer for ^#!.*/fish\s
and resets the filetype option to fish
? Or is there a policy that the filetype
option should only be automatically set once per window?
Or is there a policy that the filetype option should only be automatically set once per window?
The issue I foresee with such an approach is that it would be dependent of the load order: it would break if fish.kak was loaded first as fish.kak would update the filetype, but the hooks from sh.kak would still get called after that.
Version of Kakoune
Kakoune v2021.11.08-204-g459c6f58
Reproducer
Ask kakoune to edit a fish shell script that has a
#!/usr/bin/fish
shebang but no file extension.Outcome
Kakoune sets the filetype option to
sh
.Expectations
It should set the filetype to
fish
. Similarly to what would be done for a file with a.fish
extension.Additional information
On my system,
file -b --mime-type
producestext/x-shellscript
for fish scripts, both with and without a.fish
file extension. This might be related to why Kakoune identifies the wrong filetype.One of the most noticeable effects of the wrong filetype is that Fish's
end
keyword is not highlighted by thesh
syntax highlighting.