Skip to content

Commit

Permalink
Allow to pass the command to execute via "-e"
Browse files Browse the repository at this point in the history
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
  • Loading branch information
vimpostor committed Nov 2, 2022
1 parent a6fc932 commit 86b106d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions wezterm-gui-subcommands/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,18 @@ pub struct StartCommand {
#[arg(long = "cwd", value_parser, value_hint=ValueHint::DirPath)]
pub cwd: Option<OsString>,

/// 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.
Expand Down
1 change: 1 addition & 0 deletions wezterm-gui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 86b106d

Please sign in to comment.