From 66e8ec1586cf6eeaa57468e07c0804fba1baaf35 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 17 Apr 2022 23:02:39 -0700 Subject: [PATCH] mux: implicitly attach the domain referenced in a SpawnCommand refs: https://github.com/wez/wezterm/issues/1874 --- docs/changelog.md | 1 + mux/src/lib.rs | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 0bfb7f874..97d546004 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -17,6 +17,7 @@ As features stabilize some brief notes about them will accumulate here. * You may now use `CTRL-n` and `CTRL-p` (in addition to the up/down arrow and vi motion keys) to change the selected row in the Launcher. Thanks to [@Junnplus](https://github.com/Junnplus)! [#1880](https://github.com/wez/wezterm/pull/1880) * Attaching multiplexer domains now attaches the first window as a tab in the active window, rather than opening a new window. [#1874](https://github.com/wez/wezterm/issues/1874) * [AttachDomain](config/lua/keyassignment/AttachDomain.md) and [DetachDomain](config/lua/keyassignment/DetachDomain.md) key assignments +* Specifying a domain name in a [SpawnCommand](config/lua/SpawnCommand.md) will cause that domain to be attached if it is in the detached state. This is useful when combined with [SwitchToWorkspace](config/lua/keyassignment/SwitchToWorkspace.md). #### Changed * Debian packages now register wezterm as an alternative for `x-terminal-emulator`. Thanks to [@xpufx](https://github.com/xpufx)! [#1883](https://github.com/wez/wezterm/pull/1883) diff --git a/mux/src/lib.rs b/mux/src/lib.rs index 40f3dabbd..b5b680122 100644 --- a/mux/src/lib.rs +++ b/mux/src/lib.rs @@ -903,9 +903,6 @@ impl Mux { .get_domain_by_name(&name) .ok_or_else(|| anyhow!("domain name {} is invalid", name))?, }; - if domain.state() == DomainState::Detached { - anyhow::bail!("Cannot spawn a tab into a Detached domain"); - } Ok(domain) } @@ -949,7 +946,7 @@ impl Mux { command_dir: Option, domain: config::keyassignment::SpawnTabDomain, ) -> anyhow::Result<(Rc, PtySize)> { - let (_pane_domain_id, _window_id, tab_id) = self + let (_pane_domain_id, window_id, tab_id) = self .resolve_pane_id(pane_id) .ok_or_else(|| anyhow!("pane_id {} invalid", pane_id))?; @@ -957,6 +954,10 @@ impl Mux { .resolve_spawn_tab_domain(Some(pane_id), &domain) .context("resolve_spawn_tab_domain")?; + if domain.state() == DomainState::Detached { + domain.attach(Some(window_id)).await?; + } + let current_pane = self .get_pane(pane_id) .ok_or_else(|| anyhow!("pane_id {} is invalid", pane_id))?; @@ -1023,6 +1024,10 @@ impl Mux { (*window_builder, size) }; + if domain.state() == DomainState::Detached { + domain.attach(Some(window_id)).await?; + } + let cwd = self.resolve_cwd( command_dir, match current_pane_id {