implemented bookmarks subcommand clean to remove entries with invalid

paths
This commit is contained in:
2025-07-03 23:48:24 +02:00
parent 86744ce8fa
commit 1005eddeb8
4 changed files with 13 additions and 1 deletions
+1 -1
View File
@@ -66,7 +66,7 @@ Style settings accept styles and one color in the following formats:
- [x] do not resolve links in bookmarks - [x] do not resolve links in bookmarks
- [x] option to show invalid paths - [x] option to show invalid paths
- [x] style option for invalid paths - [x] style option for invalid paths
- [ ] option & subcommand to remove invalid paths - [x] subcommand to remove invalid paths
- [x] push <number> to push path in stack - [x] push <number> to push path in stack
- [x] write documentation - [x] write documentation
- [x] change config file extension to `.toml` - [x] change config file extension to `.toml`
+3
View File
@@ -103,6 +103,9 @@ pub enum BookmarkAction {
/// remove a bookmark by name `book remove <name>` /// remove a bookmark by name `book remove <name>`
remove(BookmarkSubArgs), remove(BookmarkSubArgs),
/// remove bookmarks with invalid paths
clean,
/// get bookmarknames for shell completions /// get bookmarknames for shell completions
completions, completions,
} }
+8
View File
@@ -101,6 +101,14 @@ impl Bookmarks {
Ok(()) 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 /// formats and prints bookmarks to string
pub fn to_formatted_string(&self, config: &Config) -> Result<String> { pub fn to_formatted_string(&self, config: &Config) -> Result<String> {
let mut buffer = String::new(); let mut buffer = String::new();
+1
View File
@@ -163,6 +163,7 @@ fn handle_bookmark(args: &BookmarkArgs, config: &Config, bookmarks: &mut Bookmar
BookmarkAction::list => list_bookmarks(config, bookmarks, output)?, BookmarkAction::list => list_bookmarks(config, bookmarks, output)?,
BookmarkAction::add(args) => add_bookmarks(args, config, bookmarks, output)?, BookmarkAction::add(args) => add_bookmarks(args, config, bookmarks, output)?,
BookmarkAction::remove(args) => remove_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()), BookmarkAction::completions => println!("echo '{}'", bookmarks.get_bookmark_names()),
}; };
} else if args.name.is_some() { // handle `change to bookmark` } else if args.name.is_some() { // handle `change to bookmark`