From 550064f80faecbe1951b249c913a7158c32ff53b Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Fri, 11 Oct 2024 21:53:37 +0300 Subject: [PATCH] Fix ~ expansion in ssh projects' terminals (#19078) When setting a remote ssh project path starting with ~, Zed would fail to cd into such project's directory when opening a new terminal. Release Notes: - N/A --------- Co-authored-by: Thorsten Ball --- crates/project/src/terminals.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/project/src/terminals.rs b/crates/project/src/terminals.rs index ecac58fb85..11b3152f0c 100644 --- a/crates/project/src/terminals.rs +++ b/crates/project/src/terminals.rs @@ -362,7 +362,16 @@ pub fn wrap_for_ssh( } let commands = if let Some(path) = path { - format!("cd {:?}; {} {}", path, env_changes, to_run) + let path_string = path.to_string_lossy().to_string(); + // shlex will wrap the command in single quotes (''), disabling ~ expansion, + // replace ith with something that works + let tilde_prefix = "~/"; + if path.starts_with(tilde_prefix) { + let trimmed_path = &path_string[tilde_prefix.len()..]; + format!("cd \"$HOME/{trimmed_path}\"; {env_changes} {to_run}") + } else { + format!("cd {path:?}; {env_changes} {to_run}") + } } else { format!("cd; {env_changes} {to_run}") };