If I have a mime type of a file using the command line file -bi
.
How do I get the associated icon of this mime type from the current appearance icons theme?
Thank you everyone.
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityThe Freedesktop.org Shared MIME Type Specification would be the applicable standard.
In short, search for the MIME type in /usr/share/mime/icons
and /usr/share/mime/generic-icons
files. If it's in there, the file tells you the name of the icon file. The first file contains icon names with exact matches to a particular MIME type; the second maps MIME types to generic icons in case there is no exactly matching icon for the file type. If there is still no hits, there are 16 or so standard icon names for generic file type icons, defined in Icon Naming Specification.
Now you know the basename of the icon. The actual icon file can be found within the /usr/share/icons/<theme name>/<icon size>/mimetypes/
directory.
How to know the <theme name>
part? Well, that still depends on which desktop environment you're using.
For the environments using the gtk toolkit, use:
gsettings get org.gnome.desktop.interface icon-theme
or for older versions:
gconftool-2 --get "/desktop/gnome/interface/icon_theme"
For KDE5, use:
kreadconfig5 --group Icons --key Theme
For older versions of KDE, drop the 5
.
For XFCE specifically, this would seem to be the command to query the icon theme name:
xfconf-query -c xsettings -p /Net/IconThemeName
Note: at the time of this writing, the Shared MIME Type Specification is still pretty new, and there may be Linux distributions that don't yet follow it. In that case, this webpage may be helpful.
gio info -a standard::icon PATH