If using xdg-open
to open applications, then use xdg-mime
to set the default application for a given mime type (typically, installing xdg-utils gives you the xdg-mime and related programs).
For example, to see the "filetype" (mime-type, if you will) of given file:
$ xdg-mime query filetype tmp.txt
text/plain
$ xdg-mime query filetype foo.pdf
application/pdf
$ xdg-mime query filetype $PWD
inode/directory
Example changing the default file manager for opening directories (could choose caja.desktop (default for mint), nautilus.desktop (ubuntu), etc:
$ xdg-mime default Thunar.desktop inode/directory
And also do locate -i foo.desktop
to verify that foo.desktop
does in fact exist.
More to the point, in order to see what the default text editor is,
$ xdg-mime query default text/plain
gedit.desktop
To use a different default text editor (again, verifying that the ".desktop" file exists):
$ locate -i vim.desktop
/usr/share/applications/gvim.desktop
$ xdg-mime default gvim.desktop text/plain
Now, either double-clicking "foo.txt" (in your GUI file manager) or running xdg-open foo.txt
will use gvim
instead of gedit
.
Troubleshooting: be sure that the ".desktop" file for a given application can be found, since that has to be used with the xdg-mime
utility; e.g.,
$ xdg-mime default emacs text/plain
xdg-mime: malformed argument 'emacs', expected *.desktop
Further, this silently fails to work as expected if the ".desktop" file does not exist:
$ locate -i emacs.desktop
(none)
$ xdg-mime default emacs.desktop text/plain # won't work
The actual emacs ".desktop" file (in my env):
$ locate -r 'emacs.*\.desktop'
/usr/share/applications/emacs24.desktop
$ xdg-mime default emacs24.desktop text/plain # does work
See also: https://wiki.archlinux.org/index.php/xdg-open
/usr/share/applications/mimecache.info
file which seems to list the default applications. It is even more confusing...~/.config/mimeapps.list