kakoune/rc/detection/file.kak

19 lines
691 B
Plaintext
Raw Normal View History

hook global BufOpenFile .* %{ evaluate-commands %sh{
if [ -z "${kak_opt_filetype}" ]; then
2019-04-17 12:37:54 +02:00
mime=$(file -b -i -L "${kak_buffile}")
mime=${mime%;*}
2016-12-07 14:00:06 +01:00
case "${mime}" in
application/*+xml) filetype="xml" ;;
2017-06-02 15:43:51 +02:00
image/*+xml) filetype="xml" ;; #SVG
message/rfc822) filetype="mail" ;;
text/x-shellscript) filetype="sh" ;;
2016-12-07 14:00:06 +01:00
text/x-*) filetype="${mime#text/x-}" ;;
text/*) filetype="${mime#text/}" ;;
application/*) filetype="${mime#application/}" ;;
2016-12-07 14:00:06 +01:00
esac
if [ -n "${filetype}" ]; then
printf "set-option buffer filetype '%s'\n" "${filetype}"
fi
fi
} }