Hello @petsam,
I’ve understood how this works but what I’m missing and can’t find is how the system selects the proper application when multiple advertise the same capability.
For example, I was interested in what opens a directory (which I expect to be the file manager). Knowing what I know now, directories have this mime type:
$ xdg-mime query filetype .
inode/directory
The lapce and visual studio code packages have .desktop
files that both advertise this capability (same as like nautilus does for gnome). For example (same is for vs code):
$ yay -Ql lapce | grep desktop
lapce /usr/share/applications/dev.lapce.lapce.desktop
$ grep -i mimetype /usr/share/applications/dev.lapce.lapce.desktop
MimeType=text/plain;inode/directory;
This is not wrong. Running either with a directory (e.g. lapce .
or code .
) as the item to open will open the application focused on that directory. However, it seems to me that the update system that parses the desktop files and generates the mime cache seems to use “alphabetical order” to decide what is used.
I had nautilus which is what I (and I suppose 90% of users) expect will be used when running xdg-open .
(i.e. open a directory with associated application should bring up a file manager). However after installing lapce
the mime cache was updated so that:
$ xdg-mime query default inode/directory
dev.lapce.lapce.desktop
If I then install VS Code, suddenly:
$ xdg-mime query default inode/directory
code.desktop
Installing them in different order yields the same result. The cache always gets:
$ grep directory /usr/share//applications/mimeinfo.cache
inode/directory=code.desktop;dev.lapce.lapce.desktop;org.gnome.Nautilus.desktop;
It seems to be alphabetical (c, l , o) ordering…
Either way, now that I understand this, I guess I can use what @Triby suggested to override: xdg-mime default org.gnome.Nautilus.desktop inode/directory
More easily, I can right-click on any folder in Nautilus, select “Open With…” and then pick “Files” from the list of applications (which I guess does the same thing behind the scenes)…
I do get it now, just annoyed with how the default behavior seems to work. It’d be better if the “order of installation” is used when generating the cache. This way installing new applications would not “surprise” you like it did for myself. Since nautilus was the first thing I installed and what was opening folders, installing lapce/code afterward should not change this unless I explicitly choose to… (but I guess that’s just my preference).