aboutsummaryrefslogtreecommitdiff
path: root/dot_config/kak/autoload/rc/detection/file.kak
diff options
context:
space:
mode:
authortwells46 <173561638+twells46@users.noreply.github.com>2025-12-31 13:28:05 -0600
committertwells46 <173561638+twells46@users.noreply.github.com>2025-12-31 13:28:05 -0600
commit2140ab51deed88e90eafebf9520fa5f9995dc7c9 (patch)
tree03cf1dcd2900495c1efb79aaa85f3254ecd5fb87 /dot_config/kak/autoload/rc/detection/file.kak
parentff8f50638e4b17a9d7cc88d2f0d9560b7effce39 (diff)
Migrate from stow
Diffstat (limited to 'dot_config/kak/autoload/rc/detection/file.kak')
-rw-r--r--dot_config/kak/autoload/rc/detection/file.kak26
1 files changed, 26 insertions, 0 deletions
diff --git a/dot_config/kak/autoload/rc/detection/file.kak b/dot_config/kak/autoload/rc/detection/file.kak
new file mode 100644
index 0000000..c707386
--- /dev/null
+++ b/dot_config/kak/autoload/rc/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