From f6b32165f20186b832f10e1d600ca59febc55e83 Mon Sep 17 00:00:00 2001 From: iobtl Date: Wed, 28 Dec 2022 23:58:52 +0800 Subject: [PATCH 1/2] args: expand `~` when parsing file paths --- helix-term/src/args.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/helix-term/src/args.rs b/helix-term/src/args.rs index dd787f1fd18c..dd4fa5905bb8 100644 --- a/helix-term/src/args.rs +++ b/helix-term/src/args.rs @@ -88,7 +88,12 @@ impl Args { /// Parse arg into [`PathBuf`] and position. pub(crate) fn parse_file(s: &str) -> (PathBuf, Position) { - let def = || (PathBuf::from(s), Position::default()); + let def = || { + ( + helix_core::path::expand_tilde(Path::new(s)), + Position::default(), + ) + }; if Path::new(s).exists() { return def(); } From 2f97a498a151003d38368e117a318b815a86b829 Mon Sep 17 00:00:00 2001 From: iobtl Date: Fri, 30 Dec 2022 00:00:49 +0800 Subject: [PATCH 2/2] args: expand tilde only in `:open` command --- helix-term/src/args.rs | 7 +------ helix-term/src/commands/typed.rs | 1 + 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/helix-term/src/args.rs b/helix-term/src/args.rs index dd4fa5905bb8..dd787f1fd18c 100644 --- a/helix-term/src/args.rs +++ b/helix-term/src/args.rs @@ -88,12 +88,7 @@ impl Args { /// Parse arg into [`PathBuf`] and position. pub(crate) fn parse_file(s: &str) -> (PathBuf, Position) { - let def = || { - ( - helix_core::path::expand_tilde(Path::new(s)), - Position::default(), - ) - }; + let def = || (PathBuf::from(s), Position::default()); if Path::new(s).exists() { return def(); } diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index c2ca1a47811b..5c0cd6543b1d 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -65,6 +65,7 @@ fn open(cx: &mut compositor::Context, args: &[Cow], event: PromptEvent) -> ensure!(!args.is_empty(), "wrong argument count"); for arg in args { let (path, pos) = args::parse_file(arg); + let path = helix_core::path::expand_tilde(&path); // If the path is a directory, open a file picker on that directory and update the status // message if let Ok(true) = std::fs::canonicalize(&path).map(|p| p.is_dir()) {