From 1a3565963ca60ee6822a1a40249ce1d84230f82b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E9=9B=85=20=C2=B7=20Misaki=20Masa?= Date: Thu, 25 Apr 2024 16:39:44 +0800 Subject: [PATCH] feat: support expanding Windows paths like "D:" that only have a drive letter but no root (#948) --- scripts/publish.sh | 2 ++ yazi-shared/Cargo.toml | 2 +- yazi-shared/src/fs/path.rs | 9 +++++++++ yazi-shared/src/lib.rs | 1 + 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/scripts/publish.sh b/scripts/publish.sh index e35ba6d2..1219d23a 100755 --- a/scripts/publish.sh +++ b/scripts/publish.sh @@ -3,7 +3,9 @@ cargo publish -p yazi-config cargo publish -p yazi-proxy cargo publish -p yazi-adaptor cargo publish -p yazi-boot +cargo publish -p yazi-dds cargo publish -p yazi-scheduler cargo publish -p yazi-plugin cargo publish -p yazi-core cargo publish -p yazi-fm +cargo publish -p yazi-cli diff --git a/yazi-shared/Cargo.toml b/yazi-shared/Cargo.toml index 5a121d3e..0fd111ff 100644 --- a/yazi-shared/Cargo.toml +++ b/yazi-shared/Cargo.toml @@ -19,7 +19,7 @@ parking_lot = "0.12.1" percent-encoding = "2.3.1" ratatui = "=0.26.1" regex = "1.10.4" -serde = "1.0.198" +serde = { version = "1.0.198", features = [ "derive" ] } tokio = { version = "1.37.0", features = [ "full" ] } # Logging diff --git a/yazi-shared/src/fs/path.rs b/yazi-shared/src/fs/path.rs index 155a120b..c145ca7c 100644 --- a/yazi-shared/src/fs/path.rs +++ b/yazi-shared/src/fs/path.rs @@ -26,6 +26,15 @@ fn _expand_path(p: &Path) -> PathBuf { env::var(name.as_str()).unwrap_or_else(|_| caps.get(0).unwrap().as_str().to_owned()) }); + // Windows paths that only have a drive letter but no root, e.g. "D:" + #[cfg(windows)] + if s.len() == 2 { + let b = s.as_bytes(); + if b[1] == b':' && b[0].is_ascii_alphabetic() { + return PathBuf::from(s.to_uppercase() + "\\"); + } + } + let p = Path::new(s.as_ref()); if let Ok(rest) = p.strip_prefix("~") { #[cfg(unix)] diff --git a/yazi-shared/src/lib.rs b/yazi-shared/src/lib.rs index 1a81d158..b9dfdcbd 100644 --- a/yazi-shared/src/lib.rs +++ b/yazi-shared/src/lib.rs @@ -26,6 +26,7 @@ pub use errors::*; pub use layer::*; pub use natsort::*; pub use number::*; +#[cfg(unix)] pub use os::*; pub use ro_cell::*; pub use throttle::*;