From 0ba1811af39e26fa3a8b78059a1e9bf053d0eb30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E9=9B=85=20misaki=20masa?= Date: Sat, 20 Jun 2026 12:47:00 +0800 Subject: [PATCH] fix: use cleaned and normalized `$PWD` as startup CWD to avoid MSYS2/git-bash path quirks (#4068) --- CHANGELOG.md | 2 ++ yazi-fs/src/cwd.rs | 9 +++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 245796e5..0240dec6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/): - Normalize `\\?\`-prefixed Verbatim paths when creating relative symlinks on Windows ([#4067]) - Keep package hashes indifferent to line endings when `ya pkg` pulls packages ([#4064]) - Use WebP as `magick` preset preloader cache format to keep image transparency ([#4065]) +- Use cleaned and normalized `$PWD` as startup CWD to avoid MSYS2/git-bash path quirks ([#4068]) ### Improved @@ -1755,3 +1756,4 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/): [#4064]: https://github.com/sxyazi/yazi/pull/4064 [#4065]: https://github.com/sxyazi/yazi/pull/4065 [#4067]: https://github.com/sxyazi/yazi/pull/4067 +[#4068]: https://github.com/sxyazi/yazi/pull/4068 diff --git a/yazi-fs/src/cwd.rs b/yazi-fs/src/cwd.rs index d5f727c3..104ea125 100644 --- a/yazi-fs/src/cwd.rs +++ b/yazi-fs/src/cwd.rs @@ -4,7 +4,7 @@ use arc_swap::ArcSwap; use yazi_shared::url::{AsUrl, Url, UrlBuf, UrlLike}; use yazi_shim::cell::RoCell; -use crate::{FsUrl, Xdg}; +use crate::{FsUrl, Xdg, path::clean_url}; pub static CWD: RoCell = RoCell::new(); @@ -18,13 +18,14 @@ impl Deref for Cwd { impl Default for Cwd { fn default() -> Self { - let p = std::env::var_os("PWD") + let u = std::env::var_os("PWD") .map(PathBuf::from) .filter(|p| p.is_absolute()) - .or_else(|| current_dir().ok()) + .map(clean_url) + .or_else(|| current_dir().ok().map(UrlBuf::from)) .expect("failed to get current working directory"); - Self(ArcSwap::new(Arc::new(UrlBuf::from(p)))) + Self(ArcSwap::new(Arc::new(u))) } }