Detect filetype on buffer save too

This allow kaking a new file, add a shebang in the first line, and get
the right filetype detected automatically on save.
This commit is contained in:
Reed Wade 2020-11-17 22:32:09 +01:00
parent cdcf4b0c7d
commit 36631fc473
No known key found for this signature in database
GPG Key ID: 5BAC92328B7C5D65

View File

@ -1,4 +1,4 @@
hook global BufOpenFile .* %{ evaluate-commands %sh{
define-command -hidden file-detection %{ evaluate-commands %sh{
if [ -z "${kak_opt_filetype}" ]; then
mime=$(file -b --mime-type -L "${kak_buffile}")
mime=${mime%;*}
@ -9,6 +9,7 @@ hook global BufOpenFile .* %{ evaluate-commands %sh{
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-*) filetype="${mime#application/x-}" ;;
application/*) filetype="${mime#application/}" ;;
@ -19,3 +20,6 @@ hook global BufOpenFile .* %{ evaluate-commands %sh{
fi
fi
} }
hook global BufOpenFile .* file-detection
hook global BufWritePost .* file-detection