How can I get kde-open to work on WSL?

At work, I run archlinux in WSL. I would like to use kde-open to open files from the terminal. Right now, it opens everything in windows programs (notepad, edge etc.) even if I have corresponding linux programs (gvim, okular) installed. Is there a way to make kde-open prioritise my preferred programs inside wsl? (I see that xdg-open does the same)

I do realise this might be an XY problem, so if there is different command that works better than kde-open, that would be fine too.

On a normal Linux system the file association is usually a combination of entries from /etc/xdg/mimeapps.list and $HOME/.config/mimeapps.list

No idea if WSL overrides one of those or if changes to either would affect the tools the way it would on “plain” Linux.

xdg-open essentially just calls the corresponding open tool of whatever desktop it has detected, e.g. kde-open in a KDE Plasma session

1 Like

Thank you, @krake.

What I can see is that xdg-mime works correctly. For instance, the command xdg-mime query default "$(xdg-mime query filetype test.txt)" gives vim.desktop as the correct output. Yet, xdg-open test.txt opens the file in notepad.

It is worth mentioning that XDG_CURRENT_DESKTOP is not set by WSL because it is not being run inside a desktop environment.

Interestingly it seems that xdg-open can even detect that it runs in WSL and then calls a Windows tool.

Just not sure why kde-open would be affected by this.

Can you try

kioclient exec file-or-URL

1 Like

You are correct that xdg-open is detecting wsl. If I run env XDG_UTILS_DEBUG_LEVEL=10 xdg-open test.txt, then it shows Selected DE wsl. Same with replacing xdg-open with kde-open.

If I run kioclient exec test.txt, I see the Choose Application - KIO Client dialog. No apps are shown in the list though. I can select /usr/bin/gvimand it opens the file correctly. However, it does not remember the selection despite selecting the checkbox to Remember application association for all files of type “Plain text document” (text/plain).

Then I am sadly out of ideas.

Thanks anyways, you really helped me identify the problem better.