Having gone through the Arch Wiki and the XDG specification in order to learn how to create my own mime types, I conducted the following experiment:
- Create a mimetype file
application-newtype.xml
in the current working directory. - Add the following contents to
application-newtype.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
<mime-type type="application/newtype">
<comment>New Type</comment>
<glob pattern="*.newtype"/>
</mime-type>
</mime-info>
- Install the mimetype locally
$ xdg-mime install application-newtype.xml
- Update mime database
$ update-mime-database ~/.local/share/mime
- Create a file with
.newtype
extension and then query the file’s mime type withxdg-mime
$ echo "Hello world" > test.newtype
$ xdg-mime query filetype test.newtype
text/plain
The result was surprising. According to xdg-mime query filetype
, test.newtype
’s mimetype is text/plain
. On the other hand, file managers such as Thunar
does report the correct mimetype.
What could possibly lead to this discrepancy? Don’t thunar
and xdg-utils
read from the same database? I though that perhaps xdg-mime
is flawed, so I tried to install other mimetype-querying tools such as the tools provided by the perl-file-mimeinfo
package.
To my surprise, after installing perl-file-meminfo
, xdg-mime query filetype
suddenly worked again.
$ sudo pacman -Syu perl-file-mimeinfo
---
---
$ xdg-mime query filetype test.newtype
application/newtype
Removing theperl-file-meminfo
altogether once again caused xdg-mime query filetype test.newtype
to yield text/plain
.
I’d really like to understand what’s going on here. Any insight is much appreciated.