aboutsummaryrefslogtreecommitdiffstats
path: root/src/local/import.rs
blob: 8db8f0e340d5ddeed38a5f954c16ea7b0ef90088 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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,
            }),
        }
    }
}