How to properly and easy configure `xdg-open` without any environment?

Why not to use utilities from xdg itself?

To make Thunar the default file-browser, i.e. the default application for opening folders.

$ xdg-mime default Thunar.desktop inode/directory

to use xpdf as the default PDF viewer:

$ xdg-mime default xpdf.desktop application/pdf

This should create an entry

[Default Applications]
application/pdf=xpdf.desktop

in your local MIME database ~/.config/mimeapps.list.

Your PDF files should be opened with xpdf now.


You can use perl-file-mimeinfo in the extra repository to manage mimetypes.

Example to open all .pdf files in apvlv:

/usr/bin/vendor_perl/mimeopen -d $file.pdf

and then, at the prompt, enter the application: apvlv.


You could use something like this to generate the appropriate xdg-mime commands for each of your .desktop files and the mimetypes they contain, then execute the ones you like. Note /usr/share/applications might have subdirectories.

find /usr/share/applications ~/.local/share/applications -iname '*.desktop' -print0 | while IFS= read -r -d $'\0' d; do
  for m in $(grep MimeType "$d" | cut -d= -f2 | tr ";" " "); do
    echo xdg-mime default "'$d'" "'$m'"
  done
done