kakoune

Fork of kakoune, an acceptable text editor
git clone git://git.laack.co/kakoune.git
Log | Files | Refs

file.kak (1084B)


      1 define-command -hidden file-detection %{ evaluate-commands %sh{
      2     if [ -z "${kak_opt_filetype}" ]; then
      3         mime=$(file -b --mime-type -L "${kak_buffile}")
      4         mime=${mime%;*}
      5         case "${mime}" in
      6             application/*+xml) filetype="xml" ;;
      7             image/*+xml) filetype="xml" ;; #SVG
      8             message/rfc822) filetype="mail" ;;
      9             text/x-shellscript) filetype="sh" ;;
     10             text/x-script.*) filetype="${mime#text/x-script.}" ;;
     11             text/x-*) filetype="${mime#text/x-}" ;;
     12             text/plain) exit ;;
     13             text/*)   filetype="${mime#text/}" ;;
     14             application/x-shellscript) filetype="sh" ;;
     15             application/x-*) filetype="${mime#application/x-}" ;;
     16             application/*) filetype="${mime#application/}" ;;
     17             *) exit ;;
     18         esac
     19         if [ -n "${filetype}" ]; then
     20             printf "set-option buffer filetype '%s'\n" "${filetype}"
     21         fi
     22     fi
     23 } }
     24 
     25 hook -group file-detection global BufOpenFile .* file-detection
     26 hook -group file-detection global BufWritePost .* file-detection