home/rc/detection/file.kak

27 lines
1.1 KiB
Plaintext
Raw Normal View History

define-command -hidden file-detection %{ evaluate-commands %sh{
if [ -z "${kak_opt_filetype}" ]; then
mime=$(file -b --mime-type -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" ;;
text/x-script.*) filetype="${mime#text/x-script.}" ;;
2016-12-07 14:00:06 +01:00
text/x-*) filetype="${mime#text/x-}" ;;
text/plain) exit ;;
2016-12-07 14:00:06 +01:00
text/*) filetype="${mime#text/}" ;;
application/x-shellscript) filetype="sh" ;;
application/x-*) filetype="${mime#application/x-}" ;;
application/*) filetype="${mime#application/}" ;;
*) exit ;;
2016-12-07 14:00:06 +01:00
esac
if [ -n "${filetype}" ]; then
printf "set-option buffer filetype '%s'\n" "${filetype}"
fi
fi
} }
hook -group file-detection global BufOpenFile .* file-detection
hook -group file-detection global BufWritePost .* file-detection