Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/duplicates removed #1247

Merged
merged 2 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 3 additions & 5 deletions atuin-client/src/import/bash.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{fs::File, io::Read, path::PathBuf, str};
use std::{path::PathBuf, str};

use async_trait::async_trait;
use directories::UserDirs;
Expand All @@ -8,6 +8,7 @@ use time::{Duration, OffsetDateTime};

use super::{get_histpath, unix_byte_lines, Importer, Loader};
use crate::history::History;
use crate::import::read_to_end;

#[derive(Debug)]
pub struct Bash {
Expand All @@ -26,10 +27,7 @@ impl Importer for Bash {
const NAME: &'static str = "bash";

async fn new() -> Result<Self> {
let mut bytes = Vec::new();
let path = get_histpath(default_histpath)?;
let mut f = File::open(path)?;
f.read_to_end(&mut bytes)?;
let bytes = read_to_end(get_histpath(default_histpath)?)?;
Ok(Self { bytes })
}

Expand Down
7 changes: 3 additions & 4 deletions atuin-client/src/import/fish.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// import old shell history!
// automatically hoover up all that we can find

use std::{fs::File, io::Read, path::PathBuf};
use std::path::PathBuf;

use async_trait::async_trait;
use directories::BaseDirs;
Expand All @@ -10,6 +10,7 @@ use time::OffsetDateTime;

use super::{unix_byte_lines, Importer, Loader};
use crate::history::History;
use crate::import::read_to_end;

#[derive(Debug)]
pub struct Fish {
Expand Down Expand Up @@ -48,9 +49,7 @@ impl Importer for Fish {
const NAME: &'static str = "fish";

async fn new() -> Result<Self> {
let mut bytes = Vec::new();
let mut f = File::open(default_histpath()?)?;
f.read_to_end(&mut bytes)?;
let bytes = read_to_end(default_histpath()?)?;
Ok(Self { bytes })
}

Expand Down
8 changes: 8 additions & 0 deletions atuin-client/src/import/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fs::File;
use std::io::Read;
use std::path::PathBuf;

use async_trait::async_trait;
Expand Down Expand Up @@ -74,6 +76,12 @@ where
}
}

fn read_to_end(path: PathBuf) -> Result<Vec<u8>> {
let mut bytes = Vec::new();
let mut f = File::open(path)?;
f.read_to_end(&mut bytes)?;
Ok(bytes)
}
fn is_file(p: PathBuf) -> Result<PathBuf> {
if p.is_file() {
Ok(p)
Expand Down
8 changes: 3 additions & 5 deletions atuin-client/src/import/nu.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// import old shell history!
// automatically hoover up all that we can find

use std::{fs::File, io::Read, path::PathBuf};
use std::path::PathBuf;

use async_trait::async_trait;
use directories::BaseDirs;
Expand All @@ -10,6 +10,7 @@ use time::OffsetDateTime;

use super::{unix_byte_lines, Importer, Loader};
use crate::history::History;
use crate::import::read_to_end;

#[derive(Debug)]
pub struct Nu {
Expand All @@ -33,10 +34,7 @@ impl Importer for Nu {
const NAME: &'static str = "nu";

async fn new() -> Result<Self> {
let mut bytes = Vec::new();
let path = get_histpath()?;
let mut f = File::open(path)?;
f.read_to_end(&mut bytes)?;
let bytes = read_to_end(get_histpath()?)?;
Ok(Self { bytes })
}

Expand Down
8 changes: 3 additions & 5 deletions atuin-client/src/import/resh.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{fs::File, io::Read, path::PathBuf};
use std::path::PathBuf;

use async_trait::async_trait;
use directories::UserDirs;
Expand All @@ -10,6 +10,7 @@ use time::OffsetDateTime;

use super::{get_histpath, unix_byte_lines, Importer, Loader};
use crate::history::History;
use crate::import::read_to_end;

#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -84,10 +85,7 @@ impl Importer for Resh {
const NAME: &'static str = "resh";

async fn new() -> Result<Self> {
let mut bytes = Vec::new();
let path = get_histpath(default_histpath)?;
let mut f = File::open(path)?;
f.read_to_end(&mut bytes)?;
let bytes = read_to_end(get_histpath(default_histpath)?)?;
Ok(Self { bytes })
}

Expand Down
8 changes: 3 additions & 5 deletions atuin-client/src/import/zsh.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// import old shell history!
// automatically hoover up all that we can find

use std::{fs::File, io::Read, path::PathBuf};
use std::path::PathBuf;

use async_trait::async_trait;
use directories::UserDirs;
Expand All @@ -10,6 +10,7 @@ use time::OffsetDateTime;

use super::{get_histpath, unix_byte_lines, Importer, Loader};
use crate::history::History;
use crate::import::read_to_end;

#[derive(Debug)]
pub struct Zsh {
Expand Down Expand Up @@ -46,10 +47,7 @@ impl Importer for Zsh {
const NAME: &'static str = "zsh";

async fn new() -> Result<Self> {
let mut bytes = Vec::new();
let path = get_histpath(default_histpath)?;
let mut f = File::open(path)?;
f.read_to_end(&mut bytes)?;
let bytes = read_to_end(get_histpath(default_histpath)?)?;
Ok(Self { bytes })
}

Expand Down