From 315ace51ed330ba6036f9664a5ff1df146421759 Mon Sep 17 00:00:00 2001 From: quak Date: Sun, 30 Mar 2025 13:20:29 +0200 Subject: [PATCH] `navigate` can now handle path with spaces, path can only be last argument though --- src/arguments.rs | 6 ++++-- src/main.rs | 10 +++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/arguments.rs b/src/arguments.rs index 97a1593..f3c95ca 100644 --- a/src/arguments.rs +++ b/src/arguments.rs @@ -42,7 +42,8 @@ pub struct PushArgs { pub show_stack: Option, /// change to - pub path: Option, + #[arg(num_args = 0..)] + pub path: Option>, } #[derive(Debug, Clone, Args)] @@ -113,7 +114,8 @@ pub struct BookmarkSubArgs { pub name: String, /// path of bookmark to add - pub path: Option, + #[arg(num_args = 0..)] + pub path: Vec, } #[derive(Debug, Clone, Args)] diff --git a/src/main.rs b/src/main.rs index 5d5f1cb..c6fe4c7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -88,7 +88,7 @@ fn handle_push(args: &PushArgs, config: &Config, stack: &mut Stack, output: &mut const PREFIX: char = '='; let mut path_string = match args.path.clone() { - Some(value) => value, + Some(value) => value.join(" "), None => { String::new() } @@ -191,9 +191,9 @@ fn list_bookmarks(config: &Config, bookmarks: &mut Bookmarks, output: &mut Outpu } fn add_bookmarks(args: &BookmarkSubArgs, config: &Config, bookmarks: &mut Bookmarks, output: &mut Output) -> Result<()> { - let mut path = match args.path.clone() { - Some(value) => value, - None => return Err(Error::other("-- missing path argument")), + let mut path : PathBuf = match PathBuf::from_str(&args.path.join(" ")) { + Ok(value) => value, + Err(error) => return Err(Error::other(error.to_string())), }; bookmarks.add_bookmark(&args.name, &path)?; @@ -230,7 +230,7 @@ fn push_path(path: &Path, stack: &mut Stack, _config: &Config, output: &mut Outp return Err(Error::other("-- invalid path argument")); } else if !(path == current_path) { stack.push_entry(¤t_path)?; - output.push_command(&format!("cd -- {}", match path.canonicalize()?.to_str() { + output.push_command(&format!("cd -- '{}'", match path.canonicalize()?.to_str() { Some(value) => value, None => return Err(Error::other("-- failed to print provided path as string")), }));