How to properly and easily configure `xdg-open` without any environment?
Solution 1
You can install and 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
or on other Linux distributions where mimeopen
is NOT in /usr/bin/vendor_perl/
but is in one of the $PATH
directories :
mimeopen -d $file.pdf
and then, at the prompt, enter the application: apvlv
.
Solution 2
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.
Solution 3
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
Solution 4
On Debian you could use the command, as root
update-mime-database /usr/share/mime
having the shared-mime-info
package installed.
Solution 5
For those like me that did not know how to get the proper mimetype to use with xdg-mime
:
1- Initial situation:
$ xdg-open .
opens vscodium (who hardcoded this stupid file association?) :[
2- Problem: what is the mime type of "."?
$ mimetype .
.: inode/directory
3- Solution:
$ xdg-mime default thunar.desktop inode/directory
NOTE: Following line doesnot work but no error is reported :{
$ xdg-mime default Thunar.desktop inode/directory
Related videos on Youtube
Comments
-
intractve almost 2 years
I'm using OpenBox window manager without any desktop environment.
xdg-open
behaves strangely. It opens everything withfirefox
.$ xdg-settings --list Known properties: default-web-browser Default web browser
I'm looking for a simple program; something like reading every
*.desktop
file in/usr/share/applications/
folder and automatically setting xdg settings.-
michael over 10 yearsusing
xdg-mime
(part ofxdg-utils
) is the best answer for working with (querying, configuring)xdg-open
. See also unix.stackexchange.com/questions/8793/… -
IanS over 3 yearsIn case someone else has this issue with
xdg-open
opening everything in Firefox, simply deleting~/.config/mimeapps.list
and restarting fxed it for me (in Ubuntu 20.04).
-
-
intractve about 12 yearsI've tried it. It doesn't work. I'm running Arch.
-
intractve about 12 yearsIt work's. But it only opens file. So my
xdg-open
left unconfigured and applications usingxdg-open
won't open files right. -
jasonwryan about 12 yearsI don't quite follow your comment. What is not working? The
-d
switch sets the default. So if you use it to openfileA.pdf
- you should then be able to openfileB.pdf
with your preferred application. -
intractve about 12 yearsYes.
mimeopen -d a.pdf
sets default for*.pdf
, but it sets default for itself -mimeopen b.pdf
works. Butxdg-open
configuration left unchanged and it still opens everything withfirefox
:/ -
jasonwryan about 12 yearsOnce I have set the default with
mimeopen
,xdg-open
behaves as expected--in the case of.pdf
s, it opens them withapvlv
. -
intractve about 12 yearsYep, thanks. It's now working. I don't know why it didn't work before. I did same.
-
michael over 10 years+1 and see also my related answer to the related question, unix.stackexchange.com/questions/77136/…
-
mVChr about 8 yearsMost useful answer, thanks. Easiest to know about
defaults.list
so it can simply be edited by hand if need be. -
Skippy le Grand Gourou almost 8 yearsFor some reason
xdg-mime
did not modifydefaults.list
, but editing it manually (thanks to hints in this answer) did the trick. -
lzap almost 8 yearsFYI few Perl dependencies are required for this, make sure you have them installed. RPM/DEB distributions will install these for you normally.
-
Nickolai Leschov over 7 yearsThis doesn't work for me in Lubuntu 16.04.
sudo xdg-mime default pluma.desktop text/plain
givestouch: cannot touch "/home/user/.local/share/applications/mimeapps.list": No such file or directory /usr/bin/xdg-mime: 807: /usr/bin/xdg-mime: cannot create /home/user/.local/share/applications/mimeapps.list.new: Directory nonexistent
;/usr/bin/vendor_perl/mimeopen -d $file.txt
givesbash: /usr/bin/vendor_perl/mimeopen: No such file or directory
. -
Mateen Ulhaq almost 7 yearsIt seems
defaults.list
is now calledmimeapps.list
. See the Arch Wiki for a list of valid locations formimeapps.list
. -
Scz over 4 yearsTo query the current default, use
xdg-mime query default application/pdf
-
Scz over 4 yearsSee user60561's answer if any .desktop file name contains spaces.
-
aleb over 4 years@Scz I copy/pasted the enhancement, I assume it works since it has been voted by 5 people. Thanks for pointing it.
-
daGo about 4 yearsto figure out mimetype of a certain file run
xdg-mime query filetype pathTofileYourInterestedIn
-
Greg Bell about 4 yearsYour result indicates that the
xdg-mime default
command isn't succeeding, or something is overwriting the mime database - maybe a nightly cron job? Editing distribution files in /usr/share/applications may solve the problem short term, but is a hack. -
Flux over 3 yearsI found my local MIME database in
~/.config/mimeapps.list
. -
Atralb over 3 years@izap, you got the path to the MIME database wrong, it is
~/.config/mimeapps.list
.