on master help sign in
fix: Expand tilde first, then deal with relative paths
2b7c086Blaž Hrastnik
helix-core/src/path.rs+2−2
@@ -40,7 +40,6 @@ pub fn expand_tilde(path: &Path) -> PathBuf {
40/// needs to improve on.
40/// needs to improve on.
41/// Copied from cargo: <https://github.com/rust-lang/cargo/blob/070e459c2d8b79c5b2ac5218064e7603329c92ae/crates/cargo-util/src/paths.rs#L81>
41/// Copied from cargo: <https://github.com/rust-lang/cargo/blob/070e459c2d8b79c5b2ac5218064e7603329c92ae/crates/cargo-util/src/paths.rs#L81>
42pub fn get_normalized_path(path: &Path) -> PathBuf {
42pub fn get_normalized_path(path: &Path) -> PathBuf {
43− let path = expand_tilde(path);
44 let mut components = path.components().peekable();
43 let mut components = path.components().peekable();
45 let mut ret = if let Some(c @ Component::Prefix(..)) = components.peek().cloned() {
44 let mut ret = if let Some(c @ Component::Prefix(..)) = components.peek().cloned() {
46 components.next();
45 components.next();
@@ -72,10 +71,11 @@ pub fn get_normalized_path(path: &Path) -> PathBuf {
72/// This function is used instead of `std::fs::canonicalize` because we don't want to verify
71/// This function is used instead of `std::fs::canonicalize` because we don't want to verify
73/// here if the path exists, just normalize it's components.
72/// here if the path exists, just normalize it's components.
74pub fn get_canonicalized_path(path: &Path) -> std::io::Result<PathBuf> {
73pub fn get_canonicalized_path(path: &Path) -> std::io::Result<PathBuf> {
74+ let path = expand_tilde(path);
75 let path = if path.is_relative() {
75 let path = if path.is_relative() {
76 std::env::current_dir().map(|current_dir| current_dir.join(path))?
76 std::env::current_dir().map(|current_dir| current_dir.join(path))?
77 } else {
77 } else {
78− path.to_path_buf()
78+ path
79 };
79 };
80
80
81 Ok(get_normalized_path(path.as_path()))
81 Ok(get_normalized_path(path.as_path()))
helix-term/src/commands.rs+1−4
@@ -1767,11 +1767,8 @@ mod cmd {
1767 args: &[&str],
1767 args: &[&str],
1768 _event: PromptEvent,
1768 _event: PromptEvent,
1769 ) -> anyhow::Result<()> {
1769 ) -> anyhow::Result<()> {
1770− use helix_core::path::expand_tilde;
1771 let path = args.get(0).context("wrong argument count")?;
1770 let path = args.get(0).context("wrong argument count")?;
1772− let _ = cx
1773− .editor
1774− .open(expand_tilde(Path::new(path)), Action::Replace)?;
1771+ let _ = cx.editor.open(path.into(), Action::Replace)?;
1775 Ok(())
1772 Ok(())
1776 }
1773 }
1777
1774