How to change the icon used to depict files of a particular type in Thunar/XFCE.
The icons displayed by Thunar are based upon information that is stored in the mimetypes database. And thus, to change a mimetype's icon, we need to modify that database. There is a Gnome gui called assogiate which might be used for this, but I haven't really tried it out yet. Or we can just modify the mimetype info manually, by editing/creating certain xml files.
As an example, I will attempt to change the icon for .html files. Firstly, I will fetch its mimetype from the commandline...
$ file --mime-type testfile.html testfile.html: text/html
Next, I need to obtain its mimetype definition info from the system's mimetype database. The database is located at /usr/share/mime/, but more specifically, the source mimetype xml definitions are found in the /usr/share/mime/packages subfolder. So, I will try to find which xml file in there contains a mime-type declaration for text/html
$ cd /usr/share/mime/packages/ $ fgrep -Hn '<mime-type type="text/html">' * freedesktop.org.xml:25295: <mime-type type="text/html">
So I have found a xml file that contains the mime-type definition for text/html. But that xml file may contain the definitions for dozens of mimetypes. So we must open it in an editor, and look for a small section of the file that begins with mime-type type="text/html" and ends with /mime-type>, as seen below.
<mime-type type="text/html"> <comment>HTML document</comment> . . . </mime-type>
Now, if we modify the systems mimetype database, it could be overwritten by a package update. So instead, we will create a new xml file in the local users mimetype database, found at ~/.local/share/mime . And since this new xml file will contain a source mimetype definition, it will be placed in the ~/.local/share/mime/packages subfolder. So, we will create a new xml file there, but using a made-up name...
$ cd ~/.local/share/mime/packages $ gedit html_example.xml &
and paste in the text found above, but adding in two extra lines to the top, and one extra line to the bottom...
<?xml version="1.0" encoding="UTF-8"?> <mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info"> <mime-type type="text/html"> <comment>HTML document</comment> . . . </mime-type> </mime-info>
In this example, on my Linux, I don't see any icon related lines in the mimetype definition for text/html. But if you see any lines similar to these...
<generic-icon name="xx_yada_yada_xx"/> <icon name="xx_blah_blah_xx"/>
then please edit them out. And finally, we will add in a icon-name entry of our own. In this case, I have chosen the icon for iceweasel, but you can choose your own. Any icon that is available on your system. Such that now, the new xml file looks similar to this
<?xml version="1.0" encoding="UTF-8"?> <mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info"> <mime-type type="text/html"> <comment>HTML document</comment> . . . <icon name="iceweasel"/> </mime-type> </mime-info>
And now save the file. Now, having modified the local mimetype source definitions, we must rebuild the local mimetypes database...
$ cd ~/.local/share/mime $ update-mime-database $PWD
If ~/.local/share/mime was empty before, then now it will contain various database files. Such that after your system has rebooted, the modified info in the local mimetype database should override the info in the main systems database. And hopefully, your html icons in Thunar will have changed too.
Well, that's how I do it. I hope that works for you. Further info on the freedesktop.org Shared MIME-info Database can be found here.