summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEllie Huxtable <e@elm.sh>2021-02-13 13:20:39 +0000
committerEllie Huxtable <e@elm.sh>2021-02-13 13:20:39 +0000
commit50ebe68d9f473a36baf9b7b913230a0e58bd26ca (patch)
tree462b97a42f179501730ed1c65da2c30ca9f1a438
parent07aceb3dd4755acdba88faea4d584ef81c08fc15 (diff)
Begin import
-rw-r--r--src/local/import.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/local/import.rs b/src/local/import.rs
new file mode 100644
index 00000000..8db8f0e3
--- /dev/null
+++ b/src/local/import.rs
@@ -0,0 +1,41 @@
+// import old shell history!
+// automatically hoover up all that we can find
+
+use std::fs::File;
+use std::io::{BufRead, BufReader};
+
+use eyre::Result;
+
+use crate::models::history::History;
+
+pub struct ImportBash {
+ file: BufReader<File>,
+}
+
+impl ImportBash {
+ pub fn new(path: &str) -> Result<ImportBash> {
+ let file = File::open(path)?;
+ let buf = BufReader::new(file);
+
+ Ok(ImportBash { file: buf })
+ }
+}
+
+impl Iterator for ImportBash {
+ type Item = History;
+
+ fn next(&mut self) -> Option<History> {
+ let mut line = String::new();
+
+ match self.file.read_line(&mut line) {
+ Ok(0) => None,
+ Err(_) => None,
+
+ Ok(_) => Some(History {
+ cwd: "none".to_string(),
+ command: line,
+ timestamp: -1,
+ }),
+ }
+ }
+}