You are not logged in.

#1 2025-05-26 07:13:11

ShwStone
Member
Registered: 2022-07-27
Posts: 11

[SOLVED] xdg-open/kde-open cannot parse vscode-remote:// protocol

I am working remotely using vscode remote ssh.

I found that when remotely calling xdg-open to try to open a file (such as automatically previewing a generated pdf), VSCode will first convert this request into a vscode-remote://ssh+devserver/my/file/path link and forward this link to the local to handle it.

Ideally, the local machine runs xdg-open vscode-remote://ssh+devserver/my/file/path, finds that this is a link of the vscode-remote protocol, calls vscode to handle it, and finally opens it normally inside vscode.

But in fact, this link is opened by my browser.

I searched a lot of information. First of all, I learned that I need to configure the .desktop file corresponding to the mime type x-scheme-handler/vscode-remote. So I configured ~/.local/share/applications/vscode-remote.desktop:

Exec=/usr/bin/code --file-uri %U

According to vscode's command line rules, the file-uri parameter is exactly the one that receives the vscode-remote:// protocol. Then I added it to ~/.config/mimeapps.list:

x-scheme-handler/vscode-remote=vscode-remote.desktop

According to the query results of xdg-mime default, the configuration was indeed successful.

Then I encountered a strange problem. If I try xdg-open vscode-remote://ssh, vscode can be successfully opened. But if I try the full link xdg-open vscode-remote://ssh+devserver/my/file/path, it fails and the browser is still opened.

The key to the problem is the plus sign. I tried several times, and once I put a plus sign in the link, the browser opened; without the plus sign, vscode opened. But the plus sign is the standard format that cannot be avoided in this link. This is very strange, and I am at my wits' end. I also tried the escape symbol %2B for the plus sign, and the result is the same.

Maybe I was going in the wrong direction in the first place? Looking forward to and grateful for any possible help.

I'm using kio 6.14.0-1, I'm sure the xdg-open is calling kde-open.

Last edited by ShwStone (2025-05-27 06:45:31)

Offline

#2 2025-05-26 13:27:18

ShwStone
Member
Registered: 2022-07-27
Posts: 11

Re: [SOLVED] xdg-open/kde-open cannot parse vscode-remote:// protocol

update: I checked gio open command:

gio open vscode-remote://ssh+devserver/my/file/path

It worked pretty well.

I guessed this is a bug of kde-open.

Now I prepare to make xdg-open a hard link of gio open. Can this be harmful?

BTW, maybe this should be reported to upstream?

Last edited by ShwStone (2025-05-26 13:27:55)

Offline

#3 2025-05-26 15:23:33

seth
Member
From: Don't DM me only for attention
Registered: 2012-09-03
Posts: 73,756

Re: [SOLVED] xdg-open/kde-open cannot parse vscode-remote:// protocol

XDG_CURRENT_DESKTOP=gnome xdg-open blafoobar

Instead of symlinks in repo-controlled paths, shadow /usr/bin/xdg-open w/ /usr/local/bin/xdg-open and make that a script calling the above ("$@" instead of blafoobar)

#!/bin/sh
exec env XDG_CURRENT_DESKTOP=gnome xdg-open "$@"

Don't forget chmod +x

Offline

#4 2025-05-27 01:56:25

ShwStone
Member
Registered: 2022-07-27
Posts: 11

Re: [SOLVED] xdg-open/kde-open cannot parse vscode-remote:// protocol

seth wrote:
XDG_CURRENT_DESKTOP=gnome xdg-open blafoobar

Instead of symlinks in repo-controlled paths, shadow /usr/bin/xdg-open w/ /usr/local/bin/xdg-open and make that a script calling the above ("$@" instead of blafoobar)

#!/bin/sh
exec env XDG_CURRENT_DESKTOP=gnome xdg-open "$@"

Don't forget chmod +x

Here is a mistake: this script calls xdg-open, which is exactly itself. It may crash the shell. Also, XDG_CURRENT_DESKTOP uses uppercase letters.

Correct version:

#!/bin/sh
exec env XDG_CURRENT_DESKTOP=GNOME /usr/bin/xdg-open "$@"

Anyway, thanks for your advice.

Offline

#5 2025-05-27 06:19:46

seth
Member
From: Don't DM me only for attention
Registered: 2012-09-03
Posts: 73,756

Re: [SOLVED] xdg-open/kde-open cannot parse vscode-remote:// protocol

Yup, sorry.
Does it workaround the problem s expected and have you filed an upstream bug against kde-open ?
https://bugs.kde.org/buglist.cgi?compon … esolution=---

Offline

#6 2025-05-27 06:45:23

ShwStone
Member
Registered: 2022-07-27
Posts: 11

Re: [SOLVED] xdg-open/kde-open cannot parse vscode-remote:// protocol

I’ve reported the bug to KDE: https://bugs.kde.org/show_bug.cgi?id=501398, which is a similar bug and I provide extra infomations. This topic is marked as SOLVED. Thanks for the support!

Offline

Board footer

Powered by FluxBB