2020-11-18 00:32:09 +03:00
|
|
|
define-command -hidden file-detection %{ evaluate-commands %sh{
|
2016-12-06 16:40:14 +03:00
|
|
|
if [ -z "${kak_opt_filetype}" ]; then
|
2020-02-22 08:25:57 +03:00
|
|
|
mime=$(file -b --mime-type -L "${kak_buffile}")
|
2019-04-17 13:35:11 +03:00
|
|
|
mime=${mime%;*}
|
2016-12-07 16:00:06 +03:00
|
|
|
case "${mime}" in
|
2016-12-14 16:40:00 +03:00
|
|
|
application/*+xml) filetype="xml" ;;
|
2017-06-02 16:43:51 +03:00
|
|
|
image/*+xml) filetype="xml" ;; #SVG
|
2016-12-14 16:40:00 +03:00
|
|
|
message/rfc822) filetype="mail" ;;
|
|
|
|
text/x-shellscript) filetype="sh" ;;
|
2020-06-12 18:21:38 +03:00
|
|
|
text/x-script.*) filetype="${mime#text/x-script.}" ;;
|
2016-12-07 16:00:06 +03:00
|
|
|
text/x-*) filetype="${mime#text/x-}" ;;
|
2020-11-18 00:32:09 +03:00
|
|
|
text/plain) exit ;;
|
2016-12-07 16:00:06 +03:00
|
|
|
text/*) filetype="${mime#text/}" ;;
|
2020-12-24 00:45:07 +03:00
|
|
|
application/x-shellscript) filetype="sh" ;;
|
2020-06-12 18:21:38 +03:00
|
|
|
application/x-*) filetype="${mime#application/x-}" ;;
|
2018-03-14 19:04:03 +03:00
|
|
|
application/*) filetype="${mime#application/}" ;;
|
2020-09-01 22:38:04 +03:00
|
|
|
*) exit ;;
|
2016-12-07 16:00:06 +03:00
|
|
|
esac
|
|
|
|
if [ -n "${filetype}" ]; then
|
2017-11-03 10:34:41 +03:00
|
|
|
printf "set-option buffer filetype '%s'\n" "${filetype}"
|
2016-12-06 16:40:14 +03:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
} }
|
2020-11-18 00:32:09 +03:00
|
|
|
|
|
|
|
hook global BufOpenFile .* file-detection
|
|
|
|
hook global BufWritePost .* file-detection
|