From 904cec3c4a329cf89fc3219d359239910d61f3f6 Mon Sep 17 00:00:00 2001 From: thing1 Date: Tue, 28 Jan 2025 09:14:32 +0000 Subject: init commit --- autoload/detection/file.kak | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 autoload/detection/file.kak (limited to 'autoload/detection/file.kak') diff --git a/autoload/detection/file.kak b/autoload/detection/file.kak new file mode 100644 index 0000000..c707386 --- /dev/null +++ b/autoload/detection/file.kak @@ -0,0 +1,26 @@ +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 -- cgit v1.2.3