diff options
| author | Jonas Maier <> | 2026-03-08 09:01:43 +0100 |
|---|---|---|
| committer | Jonas Maier <> | 2026-03-08 09:01:43 +0100 |
| commit | ce05ae9b6512820c4600c98e6c879ea5dbed8d2b (patch) | |
| tree | 3bb623fd71563e1bf4eb492c5257750897c5df74 /src/run | |
| parent | 0a1b056c7ae1caca44eba8d3073c46f7263f36ba (diff) | |
| download | pish-ce05ae9b6512820c4600c98e6c879ea5dbed8d2b.tar.gz | |
add strict mode to history
Diffstat (limited to 'src/run')
| -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" ")?; |
