My xdg-mime
makes mistakes. It recognizes an .html file containing Java code as a C++ file.
I don't quite know the internal mechanism of xdg (eg. how it determines filetype). And I want to know how to fix this problem by giving preference to judgement by filename extensions.
Of course other solutions are welcome. And explanation of mechanisms of xdg-* is even more welcome.
Best Answer
xdg-mime is part of a collection of scripts called xdg-utils, "a set of common interfaces for desktop environments (DE)". In your particular case, I'll just quote MestreLion's comment from here:
As to the internal mechanics of xdg-utils... They're just shell scripts checking for a DE and, IF found, calling that particular DE's file tools to perform a certain task. In GNOME xdg-open calls gvfs-open and xdg-mime calls gvfs-info (both gvfs-* tools giving preference to judgement by file extension). In your case, no DE is found so xdg-mime falls back to
file
[1] to get information about the file content type. Here is the code section from xdg-mime for "generic" DE (or rather unknown):Though it is true
file
[1] results are not always 100% accurate, there's not much you can do about that (it's still the best tool for this job IMO). However, if you want to determine the mime types based only on files extensions (a la windows) you could write your own script. Here is a simple python example:Name it pymime and run: