From 27255b22de3af5f87613dd2b3da4e87ab5f52537 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Sat, 18 Nov 2023 11:28:54 +0800 Subject: [PATCH] fix: avoid expanding paths for non-regular URLs --- yazi-config/src/boot/boot.rs | 6 +++--- yazi-core/src/tab/commands/cd.rs | 8 +++++--- yazi-core/src/tab/commands/reveal.rs | 7 ++++++- yazi-shared/src/fns.rs | 6 ------ 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/yazi-config/src/boot/boot.rs b/yazi-config/src/boot/boot.rs index 7673d753..ce21ecd1 100644 --- a/yazi-config/src/boot/boot.rs +++ b/yazi-config/src/boot/boot.rs @@ -19,11 +19,11 @@ pub struct Boot { impl Boot { fn parse_entry(entry: Option) -> (PathBuf, Option) { - let Some(entry) = entry else { - return (env::current_dir().unwrap(), None); + let entry = match entry { + Some(p) => expand_path(p), + None => return (env::current_dir().unwrap(), None), }; - let entry = expand_path(entry); let parent = entry.parent(); if parent.is_none() || entry.is_dir() { return (entry, None); diff --git a/yazi-core/src/tab/commands/cd.rs b/yazi-core/src/tab/commands/cd.rs index 457ea7f0..6c3d5e50 100644 --- a/yazi-core/src/tab/commands/cd.rs +++ b/yazi-core/src/tab/commands/cd.rs @@ -14,10 +14,12 @@ pub struct Opt { impl From<&Exec> for Opt { fn from(e: &Exec) -> Self { - Self { - target: Url::from(expand_path(e.args.first().map(|s| s.as_str()).unwrap_or(""))), - interactive: e.named.contains_key("interactive"), + let mut target = Url::from(e.args.first().map(|s| s.as_str()).unwrap_or("")); + if target.is_regular() { + target.set_path(expand_path(&target)) } + + Self { target, interactive: e.named.contains_key("interactive") } } } impl From for Opt { diff --git a/yazi-core/src/tab/commands/reveal.rs b/yazi-core/src/tab/commands/reveal.rs index 539e9ece..8d37dadb 100644 --- a/yazi-core/src/tab/commands/reveal.rs +++ b/yazi-core/src/tab/commands/reveal.rs @@ -9,7 +9,12 @@ pub struct Opt { impl From<&Exec> for Opt { fn from(e: &Exec) -> Self { - Self { target: Url::from(expand_path(e.args.first().map(|s| s.as_str()).unwrap_or(""))) } + let mut target = Url::from(e.args.first().map(|s| s.as_str()).unwrap_or("")); + if target.is_regular() { + target.set_path(expand_path(&target)) + } + + Self { target } } } impl From for Opt { diff --git a/yazi-shared/src/fns.rs b/yazi-shared/src/fns.rs index 22ee445e..f5d4eb90 100644 --- a/yazi-shared/src/fns.rs +++ b/yazi-shared/src/fns.rs @@ -38,12 +38,6 @@ fn _expand_path(p: &Path) -> PathBuf { #[inline] pub fn expand_path(p: impl AsRef) -> PathBuf { _expand_path(p.as_ref()) } -#[inline] -pub fn expand_url(mut u: Url) -> Url { - u.set_path(_expand_path(&u)); - u -} - #[inline] pub fn ends_with_slash(p: &Path) -> bool { // TODO: uncomment this when Rust 1.74 is released