implemented popping multiple entries at once

This commit is contained in:
2024-12-08 11:29:15 +01:00
parent 036e3d3574
commit e3d43755b1
4 changed files with 17 additions and 10 deletions
+7 -1
View File
@@ -17,7 +17,6 @@ pub struct Bookmarks {
bookmarks: HashMap<String, PathBuf>,
}
impl Bookmarks {
const BOOKMARK_FILE_NAME: &str = "bookmarks.conf";
@@ -46,9 +45,16 @@ impl Bookmarks {
/// reads and parses the bookmarks file
fn build_bookmarks(&mut self) -> Result<()> {
// check if configuration directory exists, if not create it
if !self.conf_dir.is_dir() {
fs::create_dir(self.conf_dir.clone())?;
}
let mut bookmark_file = self.conf_dir.clone();
bookmark_file.push(Self::BOOKMARK_FILE_NAME);
// check if bookmarks file exists, if not create it
if !bookmark_file.is_file() {
_ = File::create(bookmark_file.clone())?;
}
+1 -1
View File
@@ -25,7 +25,7 @@ fn main() -> Result<()> {
return Ok(());
}
};
let mut config = match Config::new() {
let config = match Config::new() {
Ok(value) => value,
Err(error) => {
print!("echo '{}{}{}' && false", style_error, error, RESET_SEQ);
+8 -7
View File
@@ -60,14 +60,15 @@ impl Stack {
/// pop entry from stack
/// return popped entry
pub fn pop_entry(&mut self, num_entries: Option<usize>) -> Result<PathBuf> {
let mut num = 1;
let mut entry: Option<PathBuf>;
if let Some(value) = num_entries {
num = value;
}
for _ in 0..num {
entry = self.stack.pop();
let mut num = num_entries.unwrap_or(1);
if num < 1 {
num = 1;
} else if num > self.stack.len() {
num = self.stack.len();
}
let mut dropped_entries = self.stack.drain((self.stack.len()-num)..);
let entry = dropped_entries.nth(0);
drop(dropped_entries);
self.write_stack_file()?;
match entry {
Some(entry) => Ok(entry),