implemented functionality of show_stack_on_push/pop
This commit is contained in:
+2
-2
@@ -29,7 +29,7 @@ pub struct Settings {
|
|||||||
pub struct GeneralSettings {
|
pub struct GeneralSettings {
|
||||||
pub show_stack_on_push: bool,
|
pub show_stack_on_push: bool,
|
||||||
pub show_stack_on_pop: bool,
|
pub show_stack_on_pop: bool,
|
||||||
pub show_stack_on_bookmark: bool,
|
pub show_books_on_bookmark: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default, ConfigParser)]
|
#[derive(Debug, Clone, Default, ConfigParser)]
|
||||||
@@ -66,7 +66,7 @@ impl Config {
|
|||||||
general: GeneralSettings {
|
general: GeneralSettings {
|
||||||
show_stack_on_push: false,
|
show_stack_on_push: false,
|
||||||
show_stack_on_pop: false,
|
show_stack_on_pop: false,
|
||||||
show_stack_on_bookmark: false,
|
show_books_on_bookmark: false,
|
||||||
},
|
},
|
||||||
format: FormatSettings {
|
format: FormatSettings {
|
||||||
bookmarks_separator: String::new(),
|
bookmarks_separator: String::new(),
|
||||||
|
|||||||
+11
-5
@@ -68,7 +68,7 @@ fn main() -> Result<()> {
|
|||||||
Ok(())
|
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() {
|
let path = match args.path.clone() {
|
||||||
Some(value) => value,
|
Some(value) => value,
|
||||||
None => {
|
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(())
|
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;
|
let mut num : Option<usize> = None;
|
||||||
if let Some(a) = &args.action {
|
if let Some(a) = &args.action {
|
||||||
match a {
|
match a {
|
||||||
@@ -96,6 +96,9 @@ fn handle_pop(args: &PopArgs, _config: &Config, stack: &mut Stack) -> Result<()>
|
|||||||
num = Some(*n);
|
num = Some(*n);
|
||||||
}
|
}
|
||||||
let path = stack.pop_entry(num)?;
|
let path = stack.pop_entry(num)?;
|
||||||
|
if config.settings.general.show_stack_on_push {
|
||||||
|
print!("echo '{}' && ", stack.to_formatted_string(&config.settings)?);
|
||||||
|
}
|
||||||
println!(
|
println!(
|
||||||
"cd -- {}",
|
"cd -- {}",
|
||||||
match path.to_str() {
|
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`
|
} else if args.name.is_some() { // handle `change to bookmark`
|
||||||
let path = bookmarks.get_path_by_name(args.name.as_ref().unwrap())?;
|
let path = bookmarks.get_path_by_name(args.name.as_ref().unwrap())?;
|
||||||
push_path(&path, stack)?;
|
push_path(&path, stack, config)?;
|
||||||
} else {
|
} else {
|
||||||
return Err(Error::other(
|
return Err(Error::other(
|
||||||
"-- provide either a `subcommand` or a `bookmark name`",
|
"-- 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
|
/// 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() {
|
if !path.is_dir() {
|
||||||
return Err(Error::other("-- invalid path argument"));
|
return Err(Error::other("-- invalid path argument"));
|
||||||
}
|
}
|
||||||
let current_path = current_dir()?;
|
let current_path = current_dir()?;
|
||||||
let next_path = path.canonicalize()?;
|
let next_path = path.canonicalize()?;
|
||||||
stack.push_entry(¤t_path)?;
|
stack.push_entry(¤t_path)?;
|
||||||
|
if config.settings.general.show_stack_on_push {
|
||||||
|
print!("echo '{}' && ", stack.to_formatted_string(&config.settings)?);
|
||||||
|
}
|
||||||
println!(
|
println!(
|
||||||
"cd -- {}",
|
"cd -- {}",
|
||||||
match next_path.to_str() {
|
match next_path.to_str() {
|
||||||
|
|||||||
@@ -3,10 +3,10 @@
|
|||||||
- [x] replace `expect` statements in 'stack.rs' with actual error handling
|
- [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] option to pop several entries at a time and option to pop the entire stack
|
||||||
- [x] drop stack
|
- [x] drop stack
|
||||||
- [ ] config file
|
- [x] config file
|
||||||
- [ ] dedup stack option
|
- [ ] dedup stack option
|
||||||
- [ ] parse config file -- partially done, handling of colors to be fixed
|
- [x] parse config file
|
||||||
- [ ] apply config -- partially done
|
- [ ] apply config -- partially more done than before :)
|
||||||
- [ ] colored output > make it configurable through config file
|
- [ ] colored output > make it configurable through config file --> at least partially done
|
||||||
- [x] setting for separator string when displaying stack/bookmarks
|
- [x] setting for separator string when displaying stack/bookmarks
|
||||||
- [x] bookmarks
|
- [x] bookmarks
|
||||||
|
|||||||
Reference in New Issue
Block a user