diff options
| -rw-r--r-- | src/run/builtin.rs | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/run/builtin.rs b/src/run/builtin.rs index 5a0c777..b566e61 100644 --- a/src/run/builtin.rs +++ b/src/run/builtin.rs @@ -248,6 +248,10 @@ struct HistoryArgs { /// displays only history of current directory here: bool, + + /// only shows if cwd perfectly matches + strict: bool, + at: Option<PathBuf>, // TODO: temporal control, i.e. before & after } @@ -266,10 +270,10 @@ impl Builtin for history { stdout: &mut dyn Write, ) -> Result { let args: HistoryArgs = read_args(args, stdout)?; - let hist = session.lock().unwrap().history.clone(); + let mut hist = session.lock().unwrap().history.clone(); let now = crate::date::DateTime::now(); - let in_dir = if args.here { + let mut in_dir = if args.here { current_dir()?.as_os_str().as_bytes().to_vec() } else if let Some(path) = args.at { path.as_os_str().as_bytes().to_vec() @@ -277,13 +281,26 @@ impl Builtin for history { Vec::new() }; + while let Some(b'/') = in_dir.last() { + in_dir.pop(); + } + // TODO: local handling (first implement global history) - for entry in hist { + for entry in hist.iter_mut() { if !entry.loc.starts_with(&in_dir) { continue; } + if args.strict { + while let Some(b'/') = entry.loc.last() { + entry.loc.pop(); + } + if entry.loc.len() != in_dir.len() { + continue; + } + } + let delta = now.relative_to(&entry.time); for _ in 0..crate::date::DateTime::longest_reasonable_delta() - delta.len() { stdout.write_all(b" ")?; |
