1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-26 08:25:50 +03:00

Always start a new process on "wezterm -e $CMD"

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
This commit is contained in:
Magnus Groß 2023-11-05 13:32:44 +01:00 committed by Wez Furlong
parent 767e72a17b
commit 191d28113e
3 changed files with 15 additions and 2 deletions

View File

@ -5,7 +5,7 @@ Usage: wezterm [OPTIONS] [COMMAND]
Commands: Commands:
start Start the GUI, optionally running an alternative start Start the GUI, optionally running an alternative
program [aliases: -e] program
ssh Establish an ssh session ssh Establish an ssh session
serial Open a serial port serial Open a serial port
connect Connect to wezterm multiplexer connect Connect to wezterm multiplexer

View File

@ -26,7 +26,6 @@ pub fn name_equals_value(arg: &str) -> Result<(String, String), String> {
#[derive(Debug, Parser, Default, Clone)] #[derive(Debug, Parser, Default, Clone)]
#[command(trailing_var_arg = true)] #[command(trailing_var_arg = true)]
#[command(visible_short_flag_alias = 'e')]
pub struct StartCommand { pub struct StartCommand {
/// If true, do not connect to domains marked as connect_automatically /// If true, do not connect to domains marked as connect_automatically
/// in your wezterm configuration file. /// in your wezterm configuration file.

View File

@ -110,6 +110,9 @@ enum SubCommand {
)] )]
Start(StartCommand), Start(StartCommand),
#[command(short_flag_alias = 'e', hide = true)]
BlockingStart(StartCommand),
#[command(name = "ssh", about = "Establish an ssh session")] #[command(name = "ssh", about = "Establish an ssh session")]
Ssh(SshCommand), Ssh(SshCommand),
@ -1195,6 +1198,16 @@ fn run() -> anyhow::Result<()> {
let config = config::configuration(); let config = config::configuration();
let sub = match opts.cmd.as_ref().cloned() { 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, Some(sub) => sub,
None => { None => {
// Need to fake an argv0 // Need to fake an argv0
@ -1218,6 +1231,7 @@ fn run() -> anyhow::Result<()> {
wezterm_blob_leases::clear_storage(); wezterm_blob_leases::clear_storage();
res res
} }
SubCommand::BlockingStart(_) => unreachable!(),
SubCommand::Ssh(ssh) => run_ssh(ssh), SubCommand::Ssh(ssh) => run_ssh(ssh),
SubCommand::Serial(serial) => run_serial(config, serial), SubCommand::Serial(serial) => run_serial(config, serial),
SubCommand::Connect(connect) => run_terminal_gui( SubCommand::Connect(connect) => run_terminal_gui(