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