You are not logged in.

#1 2022-05-23 20:16:27

$nake
Member
Registered: 2014-10-18
Posts: 30

[Solved] xdg-open fails to open text files with vim

Very similar to [Solved] xdg-open to open text files in terminal vim.

Trying to configure XDG MIME Applications for opening text files with vim in a terminal. First copying default system configuration

$ cat ~/.local/share/mime/application/vim.desktop                                      
[Desktop Entry]
Name=Vim Text Editor
Comment=Edit text files
Exec=vim %F
Terminal=true
Type=Application
Icon=terminal
Categories=Utility;TextEditor;
StartupNotify=true
MimeType=text/plain;

Checking the right xdg-mime types and rules

$ xdg-mime query filetype test.txt
text/plain
$ xdg-mime query default text/plain
.local/share/mime/application/vim.desktop
MimeType=text/plain;

But

xdg-open test.txt

fails; falling back after one second to opening the file with my default web browser.
Also trying in vim.desktop

Exec=/usr/bin/urxvt -e /usr/bin/vim %F
Terminal=false

to no avail; fails with same behavior.

Last edited by $nake (2022-05-24 09:07:43)

Offline

#2 2022-05-23 21:16:55

lmn
Member
Registered: 2021-05-09
Posts: 67

Re: [Solved] xdg-open fails to open text files with vim

Your path for the desktop file seems to be a custom one, generally it is `$XDG_DATA_HOME/applications/` which defaults to `$HOME/.local/share/applications` (see the missing mime directory).
It seems as xdg-open does not allow for paths to a .desktop file (at least in my testing). Have you tried putting your vim.desktop in the standard location? Do you have a special need for the mime directory?  How did you set that default?

Can you provide a reference that paths are allowed as MIME registries? Checking [1] and [2] does not give that impression. Also your path is relative, that could also lead to some undesired behavior.

[1] https://specifications.freedesktop.org/ … atest.html
[2] https://specifications.freedesktop.org/ … 01s07.html

Edit: It opening in a web browser seems to be the default fallback on my machine too, (probably some fallback mechanism that selects firefox as is registers at least one text/* mime type)

Last edited by lmn (2022-05-23 21:31:25)

Offline

#3 2022-05-23 21:42:11

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,522
Website

Re: [Solved] xdg-open fails to open text files with vim

The above is correct: you set the handler to a desktop file name, not a path.  Xdg-open then looks for a matching file in the appropriate directories.

However, in addition to this, why are you writing your own vim.desktop file anyways?  The vim package provides one already that is is a proper path location so it can be used as-is.  The only reason it's failing is that you overrided the setting to specify a nonsensical setting as a handler for text/plain.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#4 2022-05-24 09:06:48

$nake
Member
Registered: 2014-10-18
Posts: 30

Re: [Solved] xdg-open fails to open text files with vim

Reverting back to the default configuration did solve the problem : using the vim.desktop provided by vim package, and specifying it for text/plain in the mimeaps.list.

The weird setting on my system must be residuals from previous fiddling; some years ago the default configuration did not work. I so rarely rely on xdg-open for text files that I did not try to fix it until recently.

I cannot provide a reference that paths are allowed as MIME registries, I might have naively thought that simply specifying a path in mimeapps.list could be used, without investigating further (and worse, using relative path). Thanks for pointing out the incoherences.

Last edited by $nake (2022-05-24 09:07:09)

Offline

Board footer

Powered by FluxBB