Well I think xdg-open should check that var. It’s set it on my machine and it works. See https://www.mankier.com/1/xdg-settings#Examples . I can’t find docs for $BROWSER at the moment but on my machine:
$ xdg-settings set default-web-browser firefox.desktop
xdg-settings: $BROWSER is set and can't be changed with xdg-settings
This may sound contrarion and I have to mince words to be polite but I’ve spent countless hours getting things to work and i’ve come to the realization that xdg-open and it’s associates and software that tries to conform to the associated spec are all 100% broken on Linux.
Here’s something really interesting- apparently xdg-open can read upto 3 files in the user home directory, not to mention it also check a global database. However, you have to be careful how you manage those 3 files. One of those files is such that it’s deleted and rewritten upon every change. So you cannot symlink it to either of the other two.
I’d love for it to work. I’d love to know if somebody can give me a single file (or two) whose contents I can change to my heart’s wish but it never works. I’ve actually thrown this challenge to a SUSE engineer who thereafter said nothing.
If this was meant for me- yes my experience is from the arch days :). And I’ve tried everything from there… Every time I see a discussion on xdg-open I say to myself, maybe, just maybe, things are better now? And I regret the following 30 minutes wasted.
It is a tricky topic. A simple way to change default files is to open nautilus, right click properties, and default application. There you can pick the right app.
If this process does not work, you system is in a broken state. May I suggest to delete anything mime-related in you home, and try again ?
If you do not find your (installed) app, then the .desktop is not visible to the xgd ecosystem. Not sure how this is supposed to happen, but I have special logic to do that in my ~/.nixpkgs/config.nix[1] copied from nixos mime setup.
Otherwise you can as I did spend countless hours to strace -ff -e trace=%files -s1000 xdg-open and the like to discover how it works, and why. You will begin to understand how complex the system is, and all the parts that need to cooperate together for the whole system to work[2].
That being said, if you want a declarative way to set the default program, I fear there is none. There may be a way to declaratively set the default default program, but that is mostly useless as any user can override that pretty easily.
There actually is. I think I’vefound the nix code which decides the global defaults (mimeapps.list?) which makes my PDFs open in inkscape. I haven’t gotten around to wasting time on that though :).
Also there doesnt have to be any complexity in the system. There is a reason why there is a freedesktop spec. Simpel- you take the global config, override with per user config (the config can have priorities maybe for each file and bam, you’ve got a system.)
The cache is generated with a listing of all the know applications for a given mime type. That one is the system one, and will only list applications installed system-wide.
xdg-open 's behavior of overriding any symlink drives me crazy since it prevents versioning it. I sent a patch maybe ~4 years ago. It is still pending.
And while xdg-open is nice, firefox doesn’t support it, ranger has its own launcher (rifle, that you can redirect to use xdg-open). There is room for improvement for sure.
Yes, I was indeed talking about my system-wide configuration - between my system-wide configuration and project-specific shell.nix configurations I haven’t felt a need to have any user-scoped configuration yet.
I’d love for it to work. I’d love to know if somebody can give me a
single file (or two) whose contents I can change to my heart’s wish
but it never works. I’ve actually thrown this challenge to a SUSE
engineer who thereafter said nothing.
This is the reason I use mimi [1], the drop-in xdg-open replacement. It works
wonders. Here’s my current mimi config:
text/: edit
application/pdf: zathura
text/html: browser
video/: vlc
image/: feh
audio/: vlc
application/x-tar: urxvt -e una
application/x-gzip: urxvt -e una
application/x-bzip2: urxvt -e una
application/x-rar: urxvt -e una
application/x-xz: urxvt -e una
application/zip: urxvt -e una
inode/directory: urxvt -e ranger
gopher: urxvt -e sacc
zoommtg: zoom-us
mailto: notmuch-emacs-mua --client --hello
spotify: /home/jb55/bin/spotify-open
To be clear (and I obviously appreciate your suggestion, thank you!), my problem is with the fact that no software can properly follow the (hopefully) simple freedesktop spec. I’ve read the spec for trash and it’s very simple. I don’t know about xdg-open but it seems to me that it cannot be difficult.
Additionally, the mime types x-scheme-handler/http and x-scheme-handler/https seem to decide what happens when I click/xdg-open a link - default-web-browser doesn’t appear to influence those.
Today I discovered an awesome alternative to xdg-open:
gio open
From nixpkgs.glib.
With gio open you can open whatever URI you have and you can configure mime types with gio mime. It works pretty reliably and I assume it integrates with Gnome’s default file opener etc.
It’s worth noting that gio open doesn’t follow the XDG spec. At some point I wasted a lot of time trying to work out some mime issue that bottomed out in the application using the non-compliant glib version.
Hello, I have a bit of code which, by my limited undestanding of nix, should work but I’m stuck at trying to modify mimeinfo.cache.
I cannot read the “current version” of mimeinfo.cache. I haven’t been able to spend more time on this but it seems like mimeinfo.cache isn’t even generated at this point?