Introduction.

I've experienced a problem to make «gnome-terminal» to open URLs with Firefox, instead of Chromium browser. Obviously, the problem concerns not only «gnome-terminal», but most (all?) Gnome applications.

Conditions.

For some reason Firefox has not been installed from DEB-package, but official tarball. The only thing I did to make it default browser was updating alternatives:

$ ln -f -s /opt/firefox/firefox /etc/alternatives/x-www-browser

It's enough for most applications, for xdg-open in Debians uses that exactly link if unable to detect neither Gnome nor KDE on your desktop.

Problem.

There are caveates of manual targeting that symlink:

$ update-alternatives --list x-www-browser
/usr/bin/chromium
/usr/bin/midori

The symlink is manually handled and may escape the user's attention in some cases. The following command can be used though:

$ update-alternatives --install /usr/local/bin/firefox \
	x-www-browser /opt/firefox/firefox 100

Meanwhile there's another Gnome specific group in the alternatives system. It is «gnome-www-browser». Let's update this group too:

$ update-alternatives --install /usr/local/bin/firefox-gnome \
	gnome-www-browser /opt/firefox/firefox 100

Alas, that is not enough for «gnome-open» utility. It'd continue to use anything but firefox for to open URLs. Simply because it uses MIME cache for the work, one can find the cache file in «/usr/share/applications/mimeinfo.cache».

Solution.

The cache is a plain-text file where one can make modifications (add firefox, etc.), but there're no priorities for them… Also you have to have a description file for firefox to add it to «mimeinfo.cache», something like «firefox.desktop».

The file «mimeinfo.cache» is generated by «update-desktop-database» from «desktop-file-utils» package. This utility looks through available applications, that registered in «/usr/share/applications» directory. Let's create «firefox.desktop».

Any other such files can be used as a stencil, I've looked at «chromium-browser.desktop»:

[Desktop Entry]
Version=1.0
Name=Firefox Web Browser
Comment=Access the Internet
Exec=/opt/firefox/firefox %U
Terminal=false
X-MultipleArgs=false
Type=Application
Icon=web-browser
Categories=Network;WebBrowser;
MimeType=text/html;text/xml;application/xhtml_xml;x-scheme-handler/http;x-scheme-handler/https;
StartupWMClass=Nightly
StartupNotify=true

Since the file saved in «/usr/share/applications/» and «update-desktop-database» has been ran then, firefox must be included into «mimeinfo.cache».

Addendum.

Well known feature of that cache is that one cannot define priorities for handlers. Also «gnome-open» does not really read the cache, but traverses «applications» directory on its own, though «mimeinfo.cache» is mandatory.

According to the Gnome's article the directory «$XDG_DATA_HOME/applications» takes precedence over system default one. If XDG_DATA_HOME variable is not set, then «$HOME/.local/share» value is used instead.

Move «firefox.desktop» here. Note that «update-desktop-database» does not regard XDG_DATA_HOME, but XDG_DATA_DIRS only (besides the system default one). Hence to update or generate «mimeinfo.cache» in per-user directory, variable XDG_DATA_DIRS must contain it:

$ env XDG_DATA_DIRS=$HOME/.local/share update-desktop-database

After that the cache should be created and desktop entry files are preferred over system defaults.

The End.