home/rc/base/file.kak
Martin Chaine 7384288e07 transform mimetype to a fallback option
The option is now used as a fallback when detection by extension fails. Some
scripts like `base/mail.kak` and `base/html.kak` still rely heavily on it.
2016-12-06 17:48:46 +01:00

14 lines
380 B
Plaintext

decl str mimetype
hook global BufOpen .* %{ %sh{
if [ -z "${kak_opt_filetype}" ]; then
mime=$(file -b --mime-type "${kak_buffile}")
printf %s\\n "${mime}" | grep -q '^text/x-'
if [ $? -eq 0 ]; then
printf "set buffer filetype '%s'\n" "${mime:7}"
else
printf "set buffer mimetype '%s'\n" "${mime}"
fi
fi
} }