implemented functionality of show_stack_on_push/pop

This commit is contained in:
2025-01-13 23:38:23 +01:00
parent 5cb08dc2c1
commit ef903ab9ec
3 changed files with 18 additions and 12 deletions
+2 -2
View File
@@ -29,7 +29,7 @@ pub struct Settings {
pub struct GeneralSettings {
pub show_stack_on_push: bool,
pub show_stack_on_pop: bool,
pub show_stack_on_bookmark: bool,
pub show_books_on_bookmark: bool,
}
#[derive(Debug, Clone, Default, ConfigParser)]
@@ -66,7 +66,7 @@ impl Config {
general: GeneralSettings {
show_stack_on_push: false,
show_stack_on_pop: false,
show_stack_on_bookmark: false,
show_books_on_bookmark: false,
},
format: FormatSettings {
bookmarks_separator: String::new(),
+11 -5
View File
@@ -68,7 +68,7 @@ fn main() -> Result<()> {
Ok(())
}
fn handle_push(args: &PushArgs, _config: &Config, stack: &mut Stack) -> Result<()> {
fn handle_push(args: &PushArgs, config: &Config, stack: &mut Stack) -> Result<()> {
let path = match args.path.clone() {
Some(value) => value,
None => {
@@ -82,11 +82,11 @@ fn handle_push(args: &PushArgs, _config: &Config, stack: &mut Stack) -> Result<(
}
}
};
push_path(&path, stack)?;
push_path(&path, stack, config)?;
Ok(())
}
fn handle_pop(args: &PopArgs, _config: &Config, stack: &mut Stack) -> Result<()> {
fn handle_pop(args: &PopArgs, config: &Config, stack: &mut Stack) -> Result<()> {
let mut num : Option<usize> = None;
if let Some(a) = &args.action {
match a {
@@ -96,6 +96,9 @@ fn handle_pop(args: &PopArgs, _config: &Config, stack: &mut Stack) -> Result<()>
num = Some(*n);
}
let path = stack.pop_entry(num)?;
if config.settings.general.show_stack_on_push {
print!("echo '{}' && ", stack.to_formatted_string(&config.settings)?);
}
println!(
"cd -- {}",
match path.to_str() {
@@ -128,7 +131,7 @@ fn handle_bookmark(args: &BookmarkArgs, config: &Config, bookmarks: &mut Bookmar
};
} else if args.name.is_some() { // handle `change to bookmark`
let path = bookmarks.get_path_by_name(args.name.as_ref().unwrap())?;
push_path(&path, stack)?;
push_path(&path, stack, config)?;
} else {
return Err(Error::other(
"-- provide either a `subcommand` or a `bookmark name`",
@@ -169,13 +172,16 @@ fn remove_bookmarks(args: &BookmarkSubArgs, config: &Config, bookmarks: &mut Boo
}
/// push path to stack and print command to navigate to provided path
fn push_path(path: &Path, stack: &mut Stack) -> Result<()> {
fn push_path(path: &Path, stack: &mut Stack, config: &Config) -> Result<()> {
if !path.is_dir() {
return Err(Error::other("-- invalid path argument"));
}
let current_path = current_dir()?;
let next_path = path.canonicalize()?;
stack.push_entry(&current_path)?;
if config.settings.general.show_stack_on_push {
print!("echo '{}' && ", stack.to_formatted_string(&config.settings)?);
}
println!(
"cd -- {}",
match next_path.to_str() {
+5 -5
View File
@@ -3,10 +3,10 @@
- [x] replace `expect` statements in 'stack.rs' with actual error handling
- [x] option to pop several entries at a time and option to pop the entire stack
- [x] drop stack
- [ ] config file
- [x] config file
- [ ] dedup stack option
- [ ] parse config file -- partially done, handling of colors to be fixed
- [ ] apply config -- partially done
- [ ] colored output > make it configurable through config file
- [x] parse config file
- [ ] apply config -- partially more done than before :)
- [ ] colored output > make it configurable through config file --> at least partially done
- [x] setting for separator string when displaying stack/bookmarks
- [x] bookmarks
- [x] bookmarks