fix: use cleaned and normalized $PWD as startup CWD to avoid MSYS2/git-bash path quirks (#4068)

This commit is contained in:
三咲雅 misaki masa 2026-06-20 12:47:00 +08:00 committed by GitHub
parent feeea673f1
commit 0ba1811af3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 4 deletions

View file

@ -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

View file

@ -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<Cwd> = 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)))
}
}