Using File Type Icons in Bluefish 2

From Bluefish Wiki
Jump to: navigation, search

Bluefish 1.0 supported an internal database of icons associated with filetypes for display in the sidebar file tree. This was a rather useful feature, allowing quick visual identification of file types in projects with large numbers of files and diverse file types. To bring Bluefish in line with best practices support for MIME types and MIME icon support as suggested by, this feature has been removed from development versions of bluefish (v1.3 and up) and won't be included in release versions going forward.

Since I've become accustomed to having these icons in Bluefish, I looked for a way to leverage the shared MIME-info database to re-introduce these icons to the sidebar file tree. As with many open source projects, documentation for the shared MIME-info database isn't, or wasn't well organized, nor always self-consistent, nor complete, (nor always accurate!), so a lot of digging, googling and experimentation went into this work.

One of my primary criteria for recreating this facility was that any custom icon configuration must be user-specific and done without modifying system-wide configuration files or databases. Modern desktops such as Gnome and KDE are complex, and system databases and config files are subject to being overwritten on software updates, not to mention the fact that any individual preferences of this sort should be user specific on any desktop system with multiple user logins. Adding these icons should also be relatively simple and reversable, and should be doable, or scriptable, in relatively few command line steps.

The specification describes the file $HOME/.local/share/mime/packages/Override.xml and indicates that this file is the proper place to put user-defined XML-formatted MIME information. Such information should take the form:

 <?xml version="1.0" encoding="UTF-8"?>
 <mime-info xmlns="">
   <mime-type type="... MIME type ...">
     <comment> ... comment ... </comment>
     <glob pattern="*..."/>
     <icon name="">
   <mime-type type="... another MIME type ...">
   ... other child elements ...
    .... etc.

The full spec for this definition can be found on this page at

The <icon> child element is optional, and if used, its name attribute should refer to a PNG or XPM icon-sized file (or a symbolic link to same) in a subdirectory composed of $HOME/.local/share/icons/hicolor/ below a size spec directory ("16x16", "32x32", etc.) below a directory called "mimetypes".

This system works well in general for modifying existing MIME types, adding additional name extensions (<glob> elements), and adding custom MIME types. Unfortunately, the <icon> child element can conflict with other implementations of the shared MIME-info database, and if an icon is specified in a user-defined Override.xml for an existing MIME type defined in the system MIME-info database, or the Gnome implementation of it, the database may become corrupted causing any application using it to segfault with no useful diagnostic information returned.

The good folks at the X Desktop Group have given us a way, hopefully, to work around this problem in the form of a couple of useful utilities which can analyze the installed shared MIME-info database implementations and install user-defined icons for specific file types. You'll need the XDG utilities, available with most distributions, installed on your system.

The steps below describe the best procedure I've found for re-introducing filetype-specific icons to the Bluefish 1.3 sidebar file tree.

1. Determine the correct MIME type for a file
Use xdg-mime to determine the MIME type of a file for which you wish to install a custom icon. Invoke it as follows:
  xdg-mime query filetype path_to_target_file
If the target file doesn't already have an assigned MIME type (other than the system default, probably application/octet-stream), create an entry in $HOME/.local/share/mime/packages/Override.xml as noted above, or see the full documentation in the Shared MIME-info Database specification. After changing Override.xml, be sure to run
  update-mime-database ~/.local/share/mime
2. Install a local icon for the MIME type
Use xdg-icon-resource to install an icon for the desired MIME type as follows:
  xdg-icon-resource install --context mimetypes --mode user --size nn full_path_to_png_or_xpm_icon_file mime_spec
The nn value of the --size option should be one of 16, 20, 24, or possibly 32, and should closely match the display width and height of the selected icon, which should be approximately square.
The icon file should be small PNG or XPM file with a display size matching the --size value, e.g. 24 x 24 pixels for --size 24.
mime_spec should be the MIME type with the slash between the type and subtype replaced with a dash, e.g. application-x-php for a MIME type of application/x-php.
For example, JavaScript files with a filename extension of .js have a MIME type of application/javascript. Assume you wish to use the 24x24 pixel image ~/etc/icons/js.png to identify files of this type in the Bluefish sidebar file tree. You can install the icon in your local shared MIME-info database with:
  xdg-icon-resource install --context mimetypes --mode user --size 24 ~/etc/icons/js.png application-javascript

Icons installed in this way will show up in every context that uses the shared MIME-info database, including the File | Open dialogs of other applications and desktop file manager listings. If you're a professional web developer, as I am, you probably won't object to a mild proliferation of icons in other contexts, and you may find it a useful way to identify files of interest in any context in which they occur.

It's possible, and visually effective, to install the same icon in a selection of sizes, assuming you have the proper graphics available, by invoking xdg-icon-resource more than once, changing the size value, each time providing a path to an appropriately-sized icon. This will provide sharp, visually pleasing icons in a variety of desktop contexts in which the displayed icons may vary in size. Small icons will be scaled up as necessary, but for file displays such as the icon view in the Gnome file manager, image pixelation may be rather obvious if a small icon must be expanded several-fold to meet the display requirements.

--Fmouse 18:28, 24 April 2009 (UTC)