From 2b7c0866538676de4e5738d82e450163ff733104 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Fri, 19 Nov 2021 12:06:19 +0900 Subject: [PATCH] fix: Expand tilde first, then deal with relative paths Otherwise the ~ gets treated as a relative path. Fixes #1107 --- helix-core/src/path.rs | 4 ++-- helix-term/src/commands.rs | 5 +---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/helix-core/src/path.rs b/helix-core/src/path.rs index 6c37cfa1c..a66444651 100644 --- a/helix-core/src/path.rs +++ b/helix-core/src/path.rs @@ -40,7 +40,6 @@ pub fn expand_tilde(path: &Path) -> PathBuf { /// needs to improve on. /// Copied from cargo: pub fn get_normalized_path(path: &Path) -> PathBuf { - let path = expand_tilde(path); let mut components = path.components().peekable(); let mut ret = if let Some(c @ Component::Prefix(..)) = components.peek().cloned() { components.next(); @@ -72,10 +71,11 @@ pub fn get_normalized_path(path: &Path) -> PathBuf { /// This function is used instead of `std::fs::canonicalize` because we don't want to verify /// here if the path exists, just normalize it's components. pub fn get_canonicalized_path(path: &Path) -> std::io::Result { + let path = expand_tilde(path); let path = if path.is_relative() { std::env::current_dir().map(|current_dir| current_dir.join(path))? } else { - path.to_path_buf() + path }; Ok(get_normalized_path(path.as_path())) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index e5cf7bb22..431265cd5 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1767,11 +1767,8 @@ mod cmd { args: &[&str], _event: PromptEvent, ) -> anyhow::Result<()> { - use helix_core::path::expand_tilde; let path = args.get(0).context("wrong argument count")?; - let _ = cx - .editor - .open(expand_tilde(Path::new(path)), Action::Replace)?; + let _ = cx.editor.open(path.into(), Action::Replace)?; Ok(()) }