home/rc/detection/file.kak
throwawayaccount12345-1 3ab88f4b7c
rc file-detection hook group
Add a group to the `file-detection` hooks.

There's no way to remove hooks without a group. With this patch, you'll be able to remove those
`file-detection` hooks manually. There's no need for two separate groups since if you wanted to
remove only one, you could run `remove-hooks` and then only add one again.


Related: #3670
2022-04-20 23:11:10 -03:00

27 lines
1.1 KiB
Plaintext

define-command -hidden file-detection %{ evaluate-commands %sh{
if [ -z "${kak_opt_filetype}" ]; then
mime=$(file -b --mime-type -L "${kak_buffile}")
mime=${mime%;*}
case "${mime}" in
application/*+xml) filetype="xml" ;;
image/*+xml) filetype="xml" ;; #SVG
message/rfc822) filetype="mail" ;;
text/x-shellscript) filetype="sh" ;;
text/x-script.*) filetype="${mime#text/x-script.}" ;;
text/x-*) filetype="${mime#text/x-}" ;;
text/plain) exit ;;
text/*) filetype="${mime#text/}" ;;
application/x-shellscript) filetype="sh" ;;
application/x-*) filetype="${mime#application/x-}" ;;
application/*) filetype="${mime#application/}" ;;
*) exit ;;
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