aboutsummaryrefslogtreecommitdiffstats
path: root/src/run/builtin.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/run/builtin.rs')
-rw-r--r--src/run/builtin.rs25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/run/builtin.rs b/src/run/builtin.rs
index 366aaa5..c3153d6 100644
--- a/src/run/builtin.rs
+++ b/src/run/builtin.rs
@@ -20,7 +20,7 @@ pub trait ArgParse: Sized {
fn parse<'a>(args: &'a [BString]) -> std::result::Result<Self, ArgParseError<'a>>;
}
-fn args<T: ArgParse>(args: &[BString], w: &mut dyn Write) -> std::result::Result<T, Error> {
+fn read_args<T: ArgParse>(args: &[BString], w: &mut dyn Write) -> std::result::Result<T, Error> {
let err = match T::parse(args) {
Ok(t) => return Ok(t),
Err(e) => e,
@@ -245,10 +245,12 @@ impl Builtin for builtins {
}
}
-#[derive(FromArgs)]
+#[derive(FromArgs, Debug)]
struct HistoryArgs {
+ /// displays only local shell session history
local: bool,
+ /// displays only history of current directory
here: bool,
at: Option<PathBuf>,
// TODO: temporal control, i.e. before & after
@@ -263,13 +265,29 @@ impl Builtin for history {
fn io(
&self,
session: Arc<Mutex<Session>>,
- _args: &[BString],
+ args: &[BString],
_stdin: &mut dyn Read,
stdout: &mut dyn Write,
) -> Result {
+ let args: HistoryArgs = read_args(args, stdout)?;
let hist = session.lock().unwrap().history.clone();
let now = crate::date::DateTime::now();
+
+ let 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()
+ } else {
+ Vec::new()
+ };
+
+ // TODO: local handling (first implement global history)
+
for entry in hist {
+ if !entry.loc.starts_with(&in_dir) {
+ continue;
+ }
+
let delta = now.relative_to(&entry.time);
for _ in 0..crate::date::DateTime::longest_reasonable_delta() - delta.len() {
stdout.write_all(b" ")?;
@@ -279,6 +297,7 @@ impl Builtin for history {
stdout.write_all(&entry.cmd)?;
stdout.write_all(b"\n")?;
}
+
Ok(())
}
}