mirror of
https://github.com/mawww/kakoune.git
synced 2024-12-29 14:44:56 +03:00
407c72d90a
This adds two things I forgot in
9a7d8df4
(Avoid accidentally using environment variables in sh scopes)
Mea culpa, the problem was that I was skipping matches with "filetype"
because that's usually just a hook parameter as in "WinSetOption filetype=.."
rg --pcre2 '\b(?!filetype=)\w+=' rc/
So I missed these two cases where a shell variable is actually called "filetype".
The one in git.kak was not a problem because show_git_cmd_output is only
ever called with sane inputs. However, file.kak does use the filetype
environment variable for many mime types, for example:
filetype=somefiletype\''; echo -debug injection; nop '\' kak /dev/null
Will run the echo since /dev/null has mime type "inode/chardevice"
22 lines
855 B
Plaintext
22 lines
855 B
Plaintext
hook global BufOpenFile .* %{ 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/*) filetype="${mime#text/}" ;;
|
|
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
|
|
} }
|