Skip to content

Commit

Permalink
Always start a new process on "wezterm -e $CMD"
Browse files Browse the repository at this point in the history
This is done for compatibility, as many tools assume that running a
command with "$TERMINAL -e $COMMAND" blocks until the command is
finished.

For example some tools delete a needed file after the command returns.
But since we always return immediately (in case --always-new-process is
not provided and if another wezterm instance is already running), this
would mean that the file is deleted before the command could do
anything.

Fixes #4523
  • Loading branch information
vimpostor authored and wez committed Feb 3, 2024
1 parent 767e72a commit 191d281
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/examples/cmd-synopsis-wezterm--help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Usage: wezterm [OPTIONS] [COMMAND]

Commands:
start Start the GUI, optionally running an alternative
program [aliases: -e]
program
ssh Establish an ssh session
serial Open a serial port
connect Connect to wezterm multiplexer
Expand Down
1 change: 0 additions & 1 deletion wezterm-gui-subcommands/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ pub fn name_equals_value(arg: &str) -> Result<(String, String), String> {

#[derive(Debug, Parser, Default, Clone)]
#[command(trailing_var_arg = true)]
#[command(visible_short_flag_alias = 'e')]
pub struct StartCommand {
/// If true, do not connect to domains marked as connect_automatically
/// in your wezterm configuration file.
Expand Down
14 changes: 14 additions & 0 deletions wezterm-gui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ enum SubCommand {
)]
Start(StartCommand),

#[command(short_flag_alias = 'e', hide = true)]
BlockingStart(StartCommand),

#[command(name = "ssh", about = "Establish an ssh session")]
Ssh(SshCommand),

Expand Down Expand Up @@ -1195,6 +1198,16 @@ fn run() -> anyhow::Result<()> {
let config = config::configuration();

let sub = match opts.cmd.as_ref().cloned() {
Some(SubCommand::BlockingStart(start)) => {
// Act as if the normal start subcommand was used,
// except that we always start a new instance.
// This is needed for compatibility, because many tools assume
// that "$TERMINAL -e $COMMAND" blocks until the command finished.
SubCommand::Start(StartCommand {
always_new_process: true,
..start
})
}
Some(sub) => sub,
None => {
// Need to fake an argv0
Expand All @@ -1218,6 +1231,7 @@ fn run() -> anyhow::Result<()> {
wezterm_blob_leases::clear_storage();
res
}
SubCommand::BlockingStart(_) => unreachable!(),
SubCommand::Ssh(ssh) => run_ssh(ssh),
SubCommand::Serial(serial) => run_serial(config, serial),
SubCommand::Connect(connect) => run_terminal_gui(
Expand Down

0 comments on commit 191d281

Please sign in to comment.