From 1005eddeb851aebc02fa05e54dfc56fcf42292ea Mon Sep 17 00:00:00 2001 From: zegonix Date: Thu, 3 Jul 2025 23:48:24 +0200 Subject: [PATCH] implemented bookmarks subcommand `clean` to remove entries with invalid paths --- README.md | 2 +- src/arguments.rs | 3 +++ src/bookmarks.rs | 8 ++++++++ src/main.rs | 1 + 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6209d82..02831b7 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ Style settings accept styles and one color in the following formats: - [x] do not resolve links in bookmarks - [x] option to show invalid paths - [x] style option for invalid paths - - [ ] option & subcommand to remove invalid paths + - [x] subcommand to remove invalid paths - [x] push to push path in stack - [x] write documentation - [x] change config file extension to `.toml` diff --git a/src/arguments.rs b/src/arguments.rs index f85eed7..05c0a5b 100644 --- a/src/arguments.rs +++ b/src/arguments.rs @@ -103,6 +103,9 @@ pub enum BookmarkAction { /// remove a bookmark by name `book remove ` remove(BookmarkSubArgs), + /// remove bookmarks with invalid paths + clean, + /// get bookmarknames for shell completions completions, } diff --git a/src/bookmarks.rs b/src/bookmarks.rs index 083d8c8..74df318 100644 --- a/src/bookmarks.rs +++ b/src/bookmarks.rs @@ -101,6 +101,14 @@ impl Bookmarks { Ok(()) } + /// + pub fn remove_invalid_paths(&mut self) -> Result<()> { + self.bookmarks.retain(|_, path| path.is_dir()); + self.write_bookmark_file()?; + + Ok(()) + } + /// formats and prints bookmarks to string pub fn to_formatted_string(&self, config: &Config) -> Result { let mut buffer = String::new(); diff --git a/src/main.rs b/src/main.rs index feacbdb..09edc60 100644 --- a/src/main.rs +++ b/src/main.rs @@ -163,6 +163,7 @@ fn handle_bookmark(args: &BookmarkArgs, config: &Config, bookmarks: &mut Bookmar BookmarkAction::list => list_bookmarks(config, bookmarks, output)?, BookmarkAction::add(args) => add_bookmarks(args, config, bookmarks, output)?, BookmarkAction::remove(args) => remove_bookmarks(args, config, bookmarks, output)?, + BookmarkAction::clean => bookmarks.remove_invalid_paths()?, BookmarkAction::completions => println!("echo '{}'", bookmarks.get_bookmark_names()), }; } else if args.name.is_some() { // handle `change to bookmark`