summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/shell/history/entry.rs4
-rw-r--r--src/shell/history/mod.rs21
-rw-r--r--src/shell/mod.rs2
3 files changed, 27 insertions, 0 deletions
diff --git a/src/shell/history/entry.rs b/src/shell/history/entry.rs
index 145e0cf..0491bf7 100644
--- a/src/shell/history/entry.rs
+++ b/src/shell/history/entry.rs
@@ -227,6 +227,10 @@ impl Entry {
&self.cmdline
}
+ pub fn start_time(&self) -> time::OffsetDateTime {
+ self.start_time
+ }
+
pub fn toggle_fullscreen(&mut self) {
if let Some(fullscreen) = self.fullscreen {
self.fullscreen = Some(!fullscreen);
diff --git a/src/shell/history/mod.rs b/src/shell/history/mod.rs
index ad6ca44..91149c1 100644
--- a/src/shell/history/mod.rs
+++ b/src/shell/history/mod.rs
@@ -123,6 +123,27 @@ impl History {
}
}
+ pub async fn save(&self) {
+ // TODO: we'll probably want some amount of flock or something here
+ let mut fh = tokio::fs::OpenOptions::new()
+ .append(true)
+ .open(crate::dirs::history_file())
+ .await
+ .unwrap();
+ for entry in &self.entries {
+ fh.write_all(
+ format!(
+ ": {}:0;{}\n",
+ entry.start_time().unix_timestamp(),
+ entry.cmd()
+ )
+ .as_bytes(),
+ )
+ .await
+ .unwrap();
+ }
+ }
+
fn visible(
&self,
repl_lines: usize,
diff --git a/src/shell/mod.rs b/src/shell/mod.rs
index 4a5c5d2..fa7147b 100644
--- a/src/shell/mod.rs
+++ b/src/shell/mod.rs
@@ -50,6 +50,8 @@ pub async fn main() -> Result<i32> {
}
}
+ shell.history.save().await;
+
Ok(0)
}