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

This commit is contained in:
sxyazi 2026-06-20 12:44:54 +08:00
parent feeea673f1
commit 6df9d13a2b
No known key found for this signature in database
2 changed files with 6 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
### Improved

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)))
}
}