From 8f684fcb95dcce267aeba9d53d4cf9ecdd06dcd3 Mon Sep 17 00:00:00 2001 From: Kunall Banerjee Date: Thu, 23 Apr 2026 04:41:05 -0400 Subject: [PATCH] terminal_view: Prevent local path resolution for remote terminals (#50268) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When opening a terminal in a remote project, skip local-only path operations (home dir fallback, shell expansion, is_dir checks) so the remote shell opens in the remote user’s home directory by default. Closes #49613. Before you mark this PR as ready for review, make sure that you have: - [ ] Added a solid test coverage and/or screenshots from doing manual testing - [x] Done a self-review taking into account security and performance aspects - [x] Aligned any UI changes with the [UI checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) Release Notes: - Prevent local path resolution for remote terminals --- crates/terminal_view/src/terminal_view.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/crates/terminal_view/src/terminal_view.rs b/crates/terminal_view/src/terminal_view.rs index 515b30f50bc..271f95bea2d 100644 --- a/crates/terminal_view/src/terminal_view.rs +++ b/crates/terminal_view/src/terminal_view.rs @@ -1979,9 +1979,13 @@ impl SearchableItem for TerminalView { } /// Gets the working directory for the given workspace, respecting the user's settings. -/// Falls back to the local home directory only for local workspaces. +/// Falls back to home directory when no project directory is available. +/// +/// For remote projects, local-only resolution (home dir fallback, shell expansion, +/// local `is_dir` checks) is skipped -- returning `None` lets the remote shell +/// open in the remote user's home directory by default. pub(crate) fn default_working_directory(workspace: &Workspace, cx: &App) -> Option { - let should_fallback_to_local_home = workspace.project().read(cx).is_local(); + let is_remote = workspace.project().read(cx).is_remote(); let directory = match &TerminalSettings::get_global(cx).working_directory { WorkingDirectory::CurrentFileDirectory => workspace .project() @@ -1991,16 +1995,17 @@ pub(crate) fn default_working_directory(workspace: &Workspace, cx: &App) -> Opti WorkingDirectory::CurrentProjectDirectory => current_project_directory(workspace, cx), WorkingDirectory::FirstProjectDirectory => first_project_directory(workspace, cx), WorkingDirectory::AlwaysHome => None, - WorkingDirectory::Always { directory } => shellexpand::full(directory) + WorkingDirectory::Always { directory } if !is_remote => shellexpand::full(directory) .ok() .map(|dir| Path::new(&dir.to_string()).to_path_buf()) .filter(|dir| dir.is_dir()), + WorkingDirectory::Always { .. } => None, }; - if should_fallback_to_local_home { - directory.or_else(dirs::home_dir) - } else { + if is_remote { directory + } else { + directory.or_else(dirs::home_dir) } }