4

I am trying to make a mimetype icon theme for gnome. I have created text-x-generic.svg for all unthemed filetype. But what I am looking for is different icons for unthemed source code (say, R, vala,awk etc) and plain-generic text file.

Is this possible?

N.B. I have tried text-x-generic.svg and text-generic.svg to differentiate the source code and plain text, but that is not what linux(gnome) understands.

reply for don_crissti's Comment Say, I have icons for ruby, and js, but not for C and R. So, file.c and file.r should show the icons for text-x-generic-unthemed-sourcecode icon. And file.dat and filename_without_extensions should show a different icons (text-generic-plaintext).

File-wise, they are different, as

$ file i.c
i.c: C source, ASCII text

$ file dos.dat
dos.dat: ASCII text

So, there should be some way.

1
4

The icons used by gnome are based on mime type hence your file.c will not be detected as text-x-generic-unthemed but as text-x-csrc and since you have no associated icon it will fallback to text-x-generic.
Ex: the icons used for .vala are: text-x-vala, text-x-generic but since there is no text-x-vala icon in my icon set, the system falls back to text-x-generic:

enter image description here

See the post here on how to determine the associated icons for a specific mime type.


In order to use a different fallback icon (e.g. text-x-unthemed) one has to customize definitions for mime types that should fall back to this particular icon and add the relevant icon (text-x-unthemed) to the icon set under mimetypes .

  1. Add the icon, then update the icon cache:

    gtk-update-icon-cache /path/to/icon_theme_directory
    
  2. Add custom definitions for mime types that should use text-x-unthemed as generic (fallback) icon if they have no corresponding icons.
    Create unthemed.xml file under ~/.local/share/mime/packages e.g.:

    <?xml version="1.0"?>
     <mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
      <mime-type type="text/x-vala">
        <comment>Vala source code</comment>
        <glob pattern="*.vala" case-sensitive="true"/>
        <generic-icon name="text-x-unthemed"/>
      </mime-type>
     </mime-info>
    

    Add other mime types to the list if needed (use vala <mime-type> block as a template).

  3. Rebuild the mime cache with:

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

The system should then fall back to text-x-unthemed icon for .vala files:

enter image description here

If a dedicated icon text-x-vala is added later on, the system will use that one, e.g.:

enter image description here


Don't forget to update the icon and mime cache each time you add/remove icons or mime type definitions.

0

Thanks to @don_crissti for the details of how it works. I have gone an alternate way for solving the problem partially. I have put different icons for text-plain and text-x-generic and text-x-script. The text-plain incorporates all the files without extensions and like of .dat, .txt etc; where text-x-[generic,script] is the fallback for others and scripts.

I agree this is an ad-hoc solution, but it solves the current problem nonetheless. (The best solution is to make icons for each files in /usr/share/mime/*)

A screenshot is added to show how it looks with only text-x-[python,xml,scripts,generic,plain]

A screenshot is added

1
  • (or) you can place the icon under ~/.local/share/icons/ aswell if you dont want this icon to be available only for current user, not all users. In my case for mime-type application/vnd.jgraph.mxfile, I placed a file under ~/.local/share/icons/application-vnd.jgraph.mxfile.png – Ashok Koyi Aug 20 '20 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.