parent
80815d9eea
commit
68c5ca9ece
4 changed files with 22 additions and 22 deletions
|
@ -3,7 +3,7 @@ use std::env;
|
|||
use eyre::Result;
|
||||
use structopt::StructOpt;
|
||||
|
||||
use crate::local::database::{Database, Sqlite};
|
||||
use crate::local::database::Database;
|
||||
use crate::local::history::History;
|
||||
|
||||
#[derive(StructOpt)]
|
||||
|
@ -41,7 +41,7 @@ fn print_list(h: &[History]) {
|
|||
}
|
||||
|
||||
impl Cmd {
|
||||
pub fn run(&self, db: &mut Sqlite) -> Result<()> {
|
||||
pub fn run(&self, db: &mut impl Database) -> Result<()> {
|
||||
match self {
|
||||
Self::Start { command: words } => {
|
||||
let command = words.join(" ");
|
||||
|
|
|
@ -5,7 +5,7 @@ use directories::UserDirs;
|
|||
use eyre::{eyre, Result};
|
||||
use structopt::StructOpt;
|
||||
|
||||
use crate::local::database::{Database, Sqlite};
|
||||
use crate::local::database::Database;
|
||||
use crate::local::history::History;
|
||||
use crate::local::import::Zsh;
|
||||
use indicatif::ProgressBar;
|
||||
|
@ -26,13 +26,13 @@ pub enum Cmd {
|
|||
}
|
||||
|
||||
impl Cmd {
|
||||
pub fn run(&self, db: &mut Sqlite) -> Result<()> {
|
||||
println!(" A'Tuin ");
|
||||
println!("=====================");
|
||||
println!(" \u{1f30d} ");
|
||||
println!(" \u{1f418}\u{1f418}\u{1f418}\u{1f418} ");
|
||||
println!(" \u{1f422} ");
|
||||
println!("=====================");
|
||||
pub fn run(&self, db: &mut impl Database) -> Result<()> {
|
||||
println!(" A'Tuin ");
|
||||
println!("======================");
|
||||
println!(" \u{1f30d} ");
|
||||
println!(" \u{1f418}\u{1f418}\u{1f418}\u{1f418} ");
|
||||
println!(" \u{1f422} ");
|
||||
println!("======================");
|
||||
println!("Importing history...");
|
||||
|
||||
match self {
|
||||
|
@ -53,7 +53,7 @@ impl Cmd {
|
|||
}
|
||||
}
|
||||
|
||||
fn import_zsh(db: &mut Sqlite) -> Result<()> {
|
||||
fn import_zsh(db: &mut impl Database) -> Result<()> {
|
||||
// oh-my-zsh sets HISTFILE=~/.zhistory
|
||||
// zsh has no default value for this var, but uses ~/.zhistory.
|
||||
// we could maybe be smarter about this in the future :)
|
||||
|
@ -65,8 +65,8 @@ fn import_zsh(db: &mut Sqlite) -> Result<()> {
|
|||
|
||||
if !histpath.exists() {
|
||||
return Err(eyre!(
|
||||
"Could not find history file at {}",
|
||||
histpath.to_str().unwrap()
|
||||
"Could not find history file {:?}. try updating $HISTFILE",
|
||||
histpath
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,7 @@ fn import_zsh(db: &mut Sqlite) -> Result<()> {
|
|||
}
|
||||
};
|
||||
|
||||
let zsh = Zsh::new(histpath.to_str().unwrap())?;
|
||||
let zsh = Zsh::new(histpath)?;
|
||||
|
||||
let progress = ProgressBar::new(zsh.loc);
|
||||
|
||||
|
@ -106,7 +106,7 @@ fn import_zsh(db: &mut Sqlite) -> Result<()> {
|
|||
db.save_bulk(&buf)?;
|
||||
progress.inc(buf.len() as u64);
|
||||
|
||||
buf = Vec::<History>::with_capacity(buf_size);
|
||||
buf.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ use eyre::Result;
|
|||
use structopt::StructOpt;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::local::database::Sqlite;
|
||||
use crate::local::database::Database;
|
||||
|
||||
mod history;
|
||||
mod import;
|
||||
|
@ -35,7 +35,7 @@ pub fn uuid_v4() -> String {
|
|||
}
|
||||
|
||||
impl AtuinCmd {
|
||||
pub fn run(self, db: &mut Sqlite) -> Result<()> {
|
||||
pub fn run(self, db: &mut impl Database) -> Result<()> {
|
||||
match self {
|
||||
Self::History(history) => history.run(db),
|
||||
Self::Import(import) => import.run(db),
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use chrono::prelude::*;
|
||||
use chrono::{Duration, Utc};
|
||||
use chrono::Duration;
|
||||
use chrono_english::{parse_date_string, Dialect};
|
||||
|
||||
use cli_table::{format::Justify, print_stdout, Cell, Style, Table};
|
||||
use eyre::{eyre, Result};
|
||||
use structopt::StructOpt;
|
||||
|
||||
use crate::local::database::{Database, Sqlite};
|
||||
use crate::local::database::Database;
|
||||
use crate::local::history::History;
|
||||
|
||||
#[derive(StructOpt)]
|
||||
|
@ -70,7 +70,7 @@ fn compute_stats(history: &[History]) -> Result<()> {
|
|||
}
|
||||
|
||||
impl Cmd {
|
||||
pub fn run(&self, db: &mut Sqlite) -> Result<()> {
|
||||
pub fn run(&self, db: &mut impl Database) -> Result<()> {
|
||||
match self {
|
||||
Self::Day { words } => {
|
||||
let words = if words.is_empty() {
|
||||
|
@ -79,10 +79,10 @@ impl Cmd {
|
|||
words.join(" ")
|
||||
};
|
||||
|
||||
let start = parse_date_string(words.as_str(), Local::now(), Dialect::Us)?;
|
||||
let start = parse_date_string(&words, Local::now(), Dialect::Us)?;
|
||||
let end = start + Duration::days(1);
|
||||
|
||||
let history = db.range(start.with_timezone(&Utc), end.with_timezone(&Utc))?;
|
||||
let history = db.range(start.into(), end.into())?;
|
||||
|
||||
compute_stats(&history)?;
|
||||
|
||||
|
|
Loading…
Reference in a new issue