xdg-mime doesn't respect $XDG_CONFIG_HOME/mimeapps.list

113 views Asked by At

It all started with Visual Studio Code crashing when I tried to open the file. After troubleshooting it seems I pinned it down to an issue with MIME. Now running against the behavior I can't wrap my head around.

Basically my handlers for images stopped working. I can create a new handler for using xdg-mime, but when I query it or try to use opener it fails to pick the right handler.

According to manual the $XDG_CONFIG_HOME/mimeapps.list is supposed to take precedence. The file has the right format. And xdg-mime seems to write to it, but can't query it for some reason.

  1. Adding new handler
~ main• ❱ env XDG_UTILS_DEBUG_LEVEL=2 xdg-mime default feh.desktop image/jpeg
make_default_kde: No kde runtime detected
make_default_generic feh.desktop image/jpeg
Updating /home/om/.config/mimeapps.list
  1. Checking it was added
~ main• ❱ cat $XDG_CONFIG_HOME/mimeapps.list | grep image/jpeg
image/jpeg=feh.desktop
  1. xdg-mime query doesn't see it, although it checks the right file first
~ main• ❱ env XDG_UTILS_DEBUG_LEVEL=2 xdg-mime query default image/jpeg
Checking /home/om/.config/mimeapps.list
Checking /home/om/.local/share/applications/mimeapps.list
Checking /home/om/.local/share/applications/mimeapps.list
Checking /home/om/.local/share/applications/defaults.list and /home/om/.local/share/applications/mimeinfo.cache
Checking /home/om/.local/share/applications/defaults.list and /home/om/.local/share/applications/mimeinfo.cache
Checking /home/om/.local/share/applications/defaults.list and /home/om/.local/share/applications/mimeinfo.cache
Checking /home/om/.local/share/applications/defaults.list and /home/om/.local/share/applications/mimeinfo.cache
1

There are 1 answers

0
Oleg Medvedyev On

In this case the problem was with environment variables. I realized that the /home/om/.local/share/applications/defaults.list was overriding the /home/om/.config/mimeapps.list.

After I symlinked defaults.list to mimeapps.list it solved the problem, but that seemed a bit hacky.

Later I discovered that I had XDG_DATA_DIRS mixed with XDG_DATA_HOME, i.e.: XDG_DATA_DIRS=$HOME/.local/share, which I suspect was confusing the system-wide mime list with user-specific. After I unset the XDG_DATA_DIRS and set XDG_DATA_HOME to $HOME/.local/share the xdg-mime no longer looks for other files:

~ main• ❱ env XDG_UTILS_DEBUG_LEVEL=2 xdg-mime query default image/jpeg
Checking /home/om/.config/mimeapps.list
feh.desktop

Ref: basedir-spec