Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[KDE] wezterm cannot be configured as default terminal because it doesn't support "-e CMD" #2622

Closed
vimpostor opened this issue Oct 12, 2022 · 6 comments
Labels
bug Something isn't working

Comments

@vimpostor
Copy link
Contributor

vimpostor commented Oct 12, 2022

What Operating System(s) are you seeing this problem on?

Linux X11

Which Wayland compositor or X11 Window manager(s) are you using?

KDE 5.25

WezTerm version

wezterm 20220905-102802-7d4b8249

Describe the bug

I have configured wezterm as the default terminal emulator in KDE and am using mutt as my default mail client.

When I run xdg-open 'mailto:test@test.com', wezterm fails to start mutt with the following error message:

ERROR  wezterm_gui > Unable to spawn -e because it doesn't exist on the filesystem and was not found in PATH; terminating

This is because KDE assumes that terminal applications use a -e CMD parameter to start a given command, which is the case for most terminal emulators, e.g. for konsole, gnome-terminal and alacritty.
On a low level KDE calls wezterm with the following cmdline for the above xdg-open:

wezterm start --cwd . -- -e mutt 'mailto:test@test.com'

It would be good if wezterm supported the -e CMD parameter as well, right now wezterm tries to start an executable with name -e.

I know that the -e CMD behaviour is not the official XDG spec, but it is how this is unofficially working for almost all other terminal emulators so it would be great if wezterm supported this as well.

Here is the current Exec line of wezterm.desktop:

Exec=wezterm start --cwd . --

And here is mutt.desktop:

Exec=mutt %u
Terminal=true

The relevant part how KDE parses the desktop file when we call xdg-open can be found here: https://github.com/KDE/kio/blob/ad27f0e299e7a7a1f4059431f882f9a4ebba71fd/src/core/desktopexecparser.cpp#L532

As you can see, KDE always prepends an -e as that has worked for most terminal emulators.

In summary we might get better compatibility, if we implement -e CMD and do the following diff on our desktop file:

-Exec=wezterm start --cwd . --
+Exec=wezterm start --cwd .

What is your opinion on this? Do you think this change makes sense, or would you rather want KDE to change its behaviour as it is "non-standard"?

@vimpostor vimpostor added the bug Something isn't working label Oct 12, 2022
@vimpostor
Copy link
Contributor Author

I also just manually tested that using Exec=wezterm start --cwd . in the desktop file does not break the functionality in Dolphin as described in #2271, and pretty much all emulators don't add -e (which in this case would be equivalent to wezterm's --) to their desktop file.

So I think implementing -e and adapting the desktop file as above would increase compatibility without breaking anything.

@wez
Copy link
Owner

wez commented Oct 12, 2022

I think the KDE behavior is problematic and there should probably at least be an issue raised against KDE to discuss it.

I'm not opposed to making small changes to wezterm make things easier in the mean time, but it's still problematic; I'm not sure how to instruct the clap crate to handle -e for this case off the top of my head, for example.

https://github.com/wez/wezterm/blob/main/assets/open-wezterm-here was added for dolphin. Maybe that concept can be extended to make that script accept and ignore -e and then pass the remaining parameters down?

Then wezterm's .desktop file can point to that script instead?

@vimpostor
Copy link
Contributor Author

vimpostor commented Oct 12, 2022

I'm not sure how to instruct the clap crate to handle -e for this case

There exists trailing_var_arg in clap exactly for this purpose

https://github.com/wez/wezterm/blob/main/assets/open-wezterm-here was added for dolphin. Maybe that concept can be extended to make that script accept and ignore -e and then pass the remaining parameters down?

Then wezterm's .desktop file can point to that script instead?

That would be a possibility but I don't think we would need to go that complicated. Also I don't really understand why the open-wezterm-here script is needed, the change in #2271 should have been sufficient, but then again I didn't test on XFCE.

I can open an issue against KDE, but I think it is unlikely they will want to drop the -e as that is the only way to pass the cmdline to other terminals such as konsole or alacritty.

@vimpostor
Copy link
Contributor Author

The upstream KDE bug is tracked at: https://bugs.kde.org/show_bug.cgi?id=460387

Let's first wait what KDE says about this, I expect they don't want to drop the -e thing.

If it is indeed not fixable on the KDE side, I can look at this myself in wezterm and make a PR for you (implementing -e support and adapting the desktop file), hopefully not breaking anything else ;)

@janbuchar
Copy link

I think the opinion of KDE devs is stated in https://bugs.kde.org/show_bug.cgi?id=459616#c4. If I understand it correctly, they want to propose a change in the FreeDesktop spec, which sounds like it may take quite some time.

vimpostor added a commit to vimpostor/wezterm that referenced this issue Oct 26, 2022
Right now wezterm already allows to pass a cmdline to execute (instead
of the shell) by calling "wezterm start" with trailing arguments, e.g.
wezterm start -- bash

However, most other terminals implement this via a "-e" option. This
seems to be adopted widely in the wild, such that some third-party
frameworks just blindly expect the user's terminal to use the "-e"
option for this.

One such notable framework is kio from KDE Plasma, that calls the user's
terminal in that way when launching a desktop file that uses
Terminal=true. [1]

To solve this problem, we add a compatibility layer by adding a dummy
"-e" option. This will then consume the "-e" leaving the remaining
arguments as trailing arguments, which will later be consumed by our
existing implementation in the "prog" option.

Given that clap does not really support multiple arguments writing to
the same destination [2], this seems like the most sane implementation,
even if it is a hack.

It seems to work reliable, even for edge cases where we pass wezterm
options as trailing arguments, e.g. the following will just work and do
the expected outcome (and will **not** parse "--position" as a wezterm
argument):
wezterm start -e echo --position 10,10

Fixes wez#2622

[1] https://bugs.kde.org/show_bug.cgi?id=459616
[2] clap-rs/clap#3146
vimpostor added a commit to vimpostor/wezterm that referenced this issue Oct 26, 2022
In a56904e the desktop file was patched
to use "wezterm start" instead of "wezterm". As an unneeded addendum
that patch also included the unnecessary addition of ending command-line
parsing by passing the "--" option at the end.

As it turns out, some consumers of wezterm's desktop file want wezterm
to parse command line flags. For example KDE's kio passes the whole
cmdline via the "-e" flag, because it is widely used for most terminal
emulators as the primary mean of passing the cmdline.

To solve this we remove the unneeded "--" again, because we now also
support the "-e" option.
After all, all trailing arguments will automatically be parsed by
wezterm as the cmdline of the program to run.
The only sideeffect of this change is that we now cannot longer start
programs that share a name with a "wezterm start" option, for example if
the user has installed an executable at /usr/bin/--always-new-process
then this edge case will not work anymore.
Given that this would be an extremely unlikely scenario, it makes more
sense to improve compatibility by supporting the usecase of passing the
cmdline with the "-e" flag.

refs: wez#2622
refs: wez#2271
refs: https://bugs.kde.org/show_bug.cgi?id=459616
vimpostor added a commit to vimpostor/wezterm that referenced this issue Nov 2, 2022
Right now wezterm already allows to pass a cmdline to execute (instead
of the shell) by calling "wezterm start" with trailing arguments, e.g.
wezterm start -- bash

However, most other terminals implement this via a "-e" option. This
seems to be adopted widely in the wild, such that some third-party
frameworks just blindly expect the user's terminal to use the "-e"
option for this.

One such notable framework is kio from KDE Plasma, that calls the user's
terminal in that way when launching a desktop file that uses
Terminal=true. [1]

To solve this problem, we add a compatibility layer by adding a dummy
"-e" option. This will then consume the "-e" leaving the remaining
arguments as trailing arguments, which will later be consumed by our
existing implementation in the "prog" option.

Given that clap does not really support multiple arguments writing to
the same destination [2], this seems like the most sane implementation,
even if it is a hack.

It seems to work reliable, even for edge cases where we pass wezterm
options as trailing arguments, e.g. the following will just work and do
the expected outcome (and will **not** parse "--position" as a wezterm
argument):
wezterm start -e echo --position 10,10

Fixes wez#2622

[1] https://bugs.kde.org/show_bug.cgi?id=459616
[2] clap-rs/clap#3146
vimpostor added a commit to vimpostor/wezterm that referenced this issue Nov 2, 2022
In a56904e the desktop file was patched
to use "wezterm start" instead of "wezterm". As an unneeded addendum
that patch also included the unnecessary addition of ending command-line
parsing by passing the "--" option at the end.

As it turns out, some consumers of wezterm's desktop file want wezterm
to parse command line flags. For example KDE's kio passes the whole
cmdline via the "-e" flag, because it is widely used for most terminal
emulators as the primary mean of passing the cmdline.

To solve this we remove the unneeded "--" again, because we now also
support the "-e" option.
After all, all trailing arguments will automatically be parsed by
wezterm as the cmdline of the program to run.
The only sideeffect of this change is that we now cannot longer start
programs that share a name with a "wezterm start" option, for example if
the user has installed an executable at /usr/bin/--always-new-process
then this edge case will not work anymore.
Given that this would be an extremely unlikely scenario, it makes more
sense to improve compatibility by supporting the usecase of passing the
cmdline with the "-e" flag.

refs: wez#2622
refs: wez#2271
refs: https://bugs.kde.org/show_bug.cgi?id=459616
@wez wez closed this as completed in 0d4cd8a Nov 4, 2022
wez pushed a commit that referenced this issue Nov 4, 2022
In a56904e the desktop file was patched
to use "wezterm start" instead of "wezterm". As an unneeded addendum
that patch also included the unnecessary addition of ending command-line
parsing by passing the "--" option at the end.

As it turns out, some consumers of wezterm's desktop file want wezterm
to parse command line flags. For example KDE's kio passes the whole
cmdline via the "-e" flag, because it is widely used for most terminal
emulators as the primary mean of passing the cmdline.

To solve this we remove the unneeded "--" again, because we now also
support the "-e" option.
After all, all trailing arguments will automatically be parsed by
wezterm as the cmdline of the program to run.
The only sideeffect of this change is that we now cannot longer start
programs that share a name with a "wezterm start" option, for example if
the user has installed an executable at /usr/bin/--always-new-process
then this edge case will not work anymore.
Given that this would be an extremely unlikely scenario, it makes more
sense to improve compatibility by supporting the usecase of passing the
cmdline with the "-e" flag.

refs: #2622
refs: #2271
refs: https://bugs.kde.org/show_bug.cgi?id=459616
wez added a commit that referenced this issue Nov 4, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Feb 3, 2023

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants