implemented bookmarks subcommand clean to remove entries with invalid
paths
This commit is contained in:
@@ -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 <number> to push path in stack
|
||||
- [x] write documentation
|
||||
- [x] change config file extension to `.toml`
|
||||
|
||||
@@ -103,6 +103,9 @@ pub enum BookmarkAction {
|
||||
/// remove a bookmark by name `book remove <name>`
|
||||
remove(BookmarkSubArgs),
|
||||
|
||||
/// remove bookmarks with invalid paths
|
||||
clean,
|
||||
|
||||
/// get bookmarknames for shell completions
|
||||
completions,
|
||||
}
|
||||
|
||||
@@ -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<String> {
|
||||
let mut buffer = String::new();
|
||||
|
||||
@@ -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`
|
||||
|
||||
Reference in New Issue
Block a user