On 30/05/2022 22:38, Max Nikulin wrote:
(let* ((file-executable (executable-find "file"))
(mime-type-file
(and file-executable
(shell-command-to-string
(format "%s --brief --mime-type --dereference %s 2>/dev/null"
; ...
)))
(mime-type (if (org-string-nw-p mime-type-file)
mime-type-file
(mailcap-extension-to-mime (or ext "")))
There is an implementation of "file" that does not support --mime-type
in particular and long options at all in general:
https://landley.net/toybox/help.html#file toybox that is installed on
Android. Windows port http://gnuwin32.sourceforge.net/packages/file.htm
looks dead, but anyway for cmd.exe "2> nul" should be used instead of
">/dev/null". It may be safer to check
(string-match-p "\\`[-a-zA-Z0-9+_.]+/[-a-zA-Z0-9+_.]+\\'"
mime-file-type)
instead of error redirection. I still think that
`mailcap-extension-to-mime' should be fallback, not just alternative to
trying file command.