From 74e55d09e121c9c0d97376e72ff988dee9f888b2 Mon Sep 17 00:00:00 2001 From: kas <16035731+exactly-one-kas@users.noreply.github.com> Date: Sun, 23 Oct 2022 00:13:37 +0200 Subject: [PATCH] Fix relative CWD path given on command line being interpreted as within the server's CWD --- wezterm-gui-subcommands/src/lib.rs | 3 ++- wezterm-gui/src/main.rs | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/wezterm-gui-subcommands/src/lib.rs b/wezterm-gui-subcommands/src/lib.rs index 46f04ff50..c8c018df6 100644 --- a/wezterm-gui-subcommands/src/lib.rs +++ b/wezterm-gui-subcommands/src/lib.rs @@ -2,6 +2,7 @@ use clap::builder::ValueParser; use clap::{Parser, ValueHint}; use config::{Dimension, GeometryOrigin, SshParameters}; use std::ffi::OsString; +use std::path::PathBuf; use std::str::FromStr; pub const DEFAULT_WINDOW_CLASS: &str = "org.wezfurlong.wezterm"; @@ -161,7 +162,7 @@ pub struct StartCommand { /// Specify the current working directory for the initially /// spawned program #[arg(long = "cwd", value_parser, value_hint=ValueHint::DirPath)] - pub cwd: Option, + pub cwd: Option, /// Dummy argument that consumes "-e" and does nothing. /// This is meant as a compatibility layer for supporting the diff --git a/wezterm-gui/src/main.rs b/wezterm-gui/src/main.rs index 372c2386b..d849702ee 100644 --- a/wezterm-gui/src/main.rs +++ b/wezterm-gui/src/main.rs @@ -15,7 +15,9 @@ use mux::ssh::RemoteSshDomain; use mux::Mux; use portable_pty::cmdbuilder::CommandBuilder; use promise::spawn::block_on; +use std::borrow::Cow; use std::collections::HashMap; +use std::env::current_dir; use std::ffi::OsString; use std::path::PathBuf; use std::rc::Rc; @@ -693,7 +695,11 @@ fn run_terminal_gui(opts: StartCommand) -> anyhow::Result<()> { config.default_cwd.as_ref(), )?; if let Some(cwd) = &opts.cwd { - builder.cwd(cwd); + builder.cwd(if cwd.is_relative() { + current_dir()?.join(cwd).into_os_string().into() + } else { + Cow::Borrowed(cwd.as_ref()) + }); } Some(builder) } else {