aboutsummaryrefslogtreecommitdiffstats
path: root/atuin-client/src/import/mod.rs
blob: 8d4aa17f5b1bd08ffef7eccb3968eee1876e2718 (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
use std::{
    io::{BufRead, BufReader, Read, Seek, SeekFrom},
    path::{Path, PathBuf},
};

use eyre::Result;

use crate::history::History;

pub mod bash;
pub mod fish;
pub mod resh;
pub mod zsh;

// this could probably be sped up
fn count_lines(buf: &mut BufReader<impl Read + Seek>) -> Result<usize> {
    let lines = buf.lines().count();
    buf.seek(SeekFrom::Start(0))?;

    Ok(lines)
}

pub trait Importer: IntoIterator<Item = Result<History>> + Sized {
    const NAME: &'static str;
    fn histpath() -> Result<PathBuf>;
    fn parse(path: impl AsRef<Path>) -> Result<Self>;
}