From 55289013ed8794ea84176bc907041bdadb598075 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 9 May 2021 08:02:35 -0700 Subject: [PATCH] `wezterm cli split-pane` now respects cwd of source pane closes: https://github.com/wez/wezterm/issues/766 --- docs/changelog.md | 1 + wezterm-mux-server-impl/src/sessionhandler.rs | 26 ++++++++++++++----- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 4bf39326f..f1c331fdd 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -14,6 +14,7 @@ As features stabilize some brief notes about them will accumulate here. * Fixed: ssh client would read `/etc/ssh/config` rather than the proper `/etc/ssh/ssh_config` * x11: support for [VoidSymbol](config/keys.md#voidsymbol) in key assignments. Thanks to [@digitallyserviced](https://github.com/digitallyserviced)! [#759](https://github.com/wez/wezterm/pull/759) * Fixed: UTF8-encoded-C1 control codes were not always recognized as control codes, and could result in a panic when later attempting to update the line. [#768](https://github.com/wez/wezterm/issues/768) +* Fixed: `wezterm cli split-pane` didn't use the current working dir of the source pane. [#766](https://github.com/wez/wezterm/issues/766) ### 20210502-154244-3f7122cb diff --git a/wezterm-mux-server-impl/src/sessionhandler.rs b/wezterm-mux-server-impl/src/sessionhandler.rs index e082a3063..511a79030 100644 --- a/wezterm-mux-server-impl/src/sessionhandler.rs +++ b/wezterm-mux-server-impl/src/sessionhandler.rs @@ -607,14 +607,26 @@ async fn split_pane(split: SplitPane, sender: PduSender) -> anyhow::Result .ok_or_else(|| anyhow!("domain name {} is invalid", name))?, }; + let pane_id = split.pane_id; + let cwd = split.command_dir.or_else(|| { + mux.get_pane(pane_id) + .and_then(|pane| pane.get_current_working_dir()) + .map(|url| { + let path = url.path().to_string(); + // On Windows the file URI can produce a path like: + // `/C:\Users` which is valid in a file URI, but the leading slash + // is not liked by the windows file APIs, so we strip it off here. + let bytes = path.as_bytes(); + if bytes.len() > 2 && bytes[0] == b'/' && bytes[2] == b':' { + path[1..].to_owned() + } else { + path + } + }) + }); + let pane = domain - .split_pane( - split.command, - split.command_dir, - tab_id, - split.pane_id, - split.direction, - ) + .split_pane(split.command, cwd, tab_id, split.pane_id, split.direction) .await?; let dims = pane.get_dimensions(); let size = PtySize {