1

I want to create new mime-type (text/something) for some kind of files. I know how to make it, but I don't know how to make the file manager to display different icons for these file types?

I am using LXDE and PCManFM, but some general solution would be better of course.

1 Answer 1

0

Let's call the new mimetype text/x-foo and assume the files all end in .foo. First, we need a mimeinfo file. It's a small XML file called x-foo.xml that looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
    <mime-type type="text/x-foo">
        <comment>FOO file</comment>
        <glob pattern="*.foo"/>
        <icon name="foo-icon"/>
    </mime-type>
</mime-info>

This line here is key:

<icon name="foo-icon"/>

since it tells applications like file managers to look for an icon called foo-icon.png or foo-icon.svg. To install the mimeinfo file, we run this command:

$ xdg-mime install --mode user x-foo.xml

Now you should see the XML file here:

~/.local/share/mime/text/x-foo.xml

Next, let's update the mime database.

update-mime-database ~/.local/share/mime

Finally, let's install the icon. One way this can be done is with the xdg-icon-resource command. For example, if you have a 48x48 PNG icon called x-foo.png, do this:

$ xdg-icon-resource install --context mimetypes --size 48 x-foo.png foo-icon

Now you should see it here:

~/.local/share/icons/hicolor/48x48/mimetypes/foo-icon.png

However, xdg-icon-resource does not support SVG images, and in practice this accomplishes the same thing:

$ cp foo-icon.svg ~/.local/share/icons/hicolor/48x48/mimetypes/
$ cp foo-icon.svg ~/.local/share/icons/hicolor/scalable/mimetypes/

(That's not a typo: put the SVG file in the 48x48/mimetypes folder and the menus and panels will be perfectly happy.)

Finally, update the icon caches.

$ update-icon-caches ~/.local/share/icons

Now your custom icon for your custom mimetype should show up in all file managers. (You may need to press F5 to refresh the icons in any open directories, or perhaps close and re-load all running instances of the file managers.)

Here's the before and after:

generic icon foo icon

Sources / related:

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .