From 0d4cd8a1e04d2a0a60224cd35c9631f72878fe39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Gro=C3=9F?= Date: Wed, 26 Oct 2022 23:10:47 +0200 Subject: [PATCH] Allow to pass the command to execute via "-e" 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 #2622 [1] https://bugs.kde.org/show_bug.cgi?id=459616 [2] https://github.com/clap-rs/clap/issues/3146 --- wezterm-gui-subcommands/src/lib.rs | 12 ++++++++++++ wezterm-gui/src/main.rs | 1 + 2 files changed, 13 insertions(+) diff --git a/wezterm-gui-subcommands/src/lib.rs b/wezterm-gui-subcommands/src/lib.rs index 06318aca9..46f04ff50 100644 --- a/wezterm-gui-subcommands/src/lib.rs +++ b/wezterm-gui-subcommands/src/lib.rs @@ -163,6 +163,18 @@ pub struct StartCommand { #[arg(long = "cwd", value_parser, value_hint=ValueHint::DirPath)] pub cwd: Option, + /// Dummy argument that consumes "-e" and does nothing. + /// This is meant as a compatibility layer for supporting the + /// widely adopted standard of passing the command to execute + /// to the terminal via a "-e" option. + /// This works because we then treat the remaining cmdline as + /// trailing options, that will automatically be parsed via the + /// existing "prog" option. + /// This option exists only as a fallback. It is recommended to pass + /// the command as a normal trailing command instead if possible. + #[arg(short = 'e', hide = true)] + pub _cmd: bool, + /// Override the default windowing system class. /// The default is "org.wezfurlong.wezterm". /// Under X11 and Windows this changes the window class. diff --git a/wezterm-gui/src/main.rs b/wezterm-gui/src/main.rs index 1cc569109..3140dfc51 100644 --- a/wezterm-gui/src/main.rs +++ b/wezterm-gui/src/main.rs @@ -143,6 +143,7 @@ async fn async_run_ssh(opts: SshCommand) -> anyhow::Result<()> { position: opts.position, workspace: None, prog: opts.prog.clone(), + ..Default::default() }; let cmd = if !opts.prog.is_empty() {