From 5fcb99a1545d5f5bcf230d40ee8afc0d69ab4bb4 Mon Sep 17 00:00:00 2001 From: Martin Chaine Date: Wed, 7 Dec 2016 14:00:06 +0100 Subject: [PATCH] smarter mimetype matching --- rc/base/file.kak | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/rc/base/file.kak b/rc/base/file.kak index 0aef21ec..89442fa9 100644 --- a/rc/base/file.kak +++ b/rc/base/file.kak @@ -3,9 +3,12 @@ decl str mimetype hook global BufOpen .* %{ %sh{ if [ -z "${kak_opt_filetype}" ]; then mime=$(file -b --mime-type "${kak_buffile}") - printf %s\\n "${mime}" | grep -q '^text/x-' - if [ $? -eq 0 ]; then - printf "set buffer filetype '%s'\n" "${mime:7}" + case "${mime}" in + text/x-*) filetype="${mime#text/x-}" ;; + text/*) filetype="${mime#text/}" ;; + esac + if [ -n "${filetype}" ]; then + printf "set buffer filetype '%s'\n" "${filetype}" else printf "set buffer mimetype '%s'\n" "${mime}" fi