From 8d50d7808ef80d351663ef068e10f1b3fb73f76d Mon Sep 17 00:00:00 2001 From: Pascal Kuthe Date: Sat, 11 May 2024 14:41:13 +0200 Subject: [PATCH 1/2] correctly handle opening helix inside symlinked directory --- helix-stdx/src/env.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/helix-stdx/src/env.rs b/helix-stdx/src/env.rs index 59aba0adc2ce..77597816ece3 100644 --- a/helix-stdx/src/env.rs +++ b/helix-stdx/src/env.rs @@ -14,13 +14,23 @@ pub fn current_working_dir() -> PathBuf { return path.clone(); } - let path = std::env::current_dir() - .map(crate::path::normalize) - .expect("Couldn't determine current working directory"); - let mut cwd = CWD.write().unwrap(); - *cwd = Some(path.clone()); + // implementation of crossplatform pwd -L + // we want pwd -L so that symlinked directories are handeled correctly + let mut cwd = std::env::current_dir().expect("Couldn't determine current working directory"); + + let pwd = std::env::var_os("PWD"); + #[cfg(windows)] + let pwd = pwd.or_else(|| std::env::var_os("CD")); + + if let Some(pwd) = pwd.map(PathBuf::from) { + if pwd.canonicalize().ok().as_ref() == Some(&cwd) { + cwd = pwd; + } + } + let mut dst = CWD.write().unwrap(); + *dst = Some(cwd.clone()); - path + cwd } pub fn set_current_working_dir(path: impl AsRef) -> std::io::Result<()> { From 8d6e4e0a21cffc8397bfc33529d9f5d1493b41e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Mon, 20 May 2024 21:44:41 +0900 Subject: [PATCH 2/2] Update helix-stdx/src/env.rs --- helix-stdx/src/env.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-stdx/src/env.rs b/helix-stdx/src/env.rs index 77597816ece3..51450d225870 100644 --- a/helix-stdx/src/env.rs +++ b/helix-stdx/src/env.rs @@ -15,7 +15,7 @@ pub fn current_working_dir() -> PathBuf { } // implementation of crossplatform pwd -L - // we want pwd -L so that symlinked directories are handeled correctly + // we want pwd -L so that symlinked directories are handled correctly let mut cwd = std::env::current_dir().expect("Couldn't determine current working directory"); let pwd = std::env::var_os("PWD");