diff --git a/atuin-client/src/database.rs b/atuin-client/src/database.rs index a6957093..05ff559a 100644 --- a/atuin-client/src/database.rs +++ b/atuin-client/src/database.rs @@ -78,7 +78,7 @@ pub trait Database: Send + Sync + 'static { async fn load(&self, id: &str) -> Result>; async fn list( &self, - filter: FilterMode, + filters: &[FilterMode], context: &Context, max: Option, unique: bool, @@ -271,7 +271,7 @@ impl Database for Sqlite { // make a unique list, that only shows the *newest* version of things async fn list( &self, - filter: FilterMode, + filters: &[FilterMode], context: &Context, max: Option, unique: bool, @@ -291,13 +291,15 @@ impl Database for Sqlite { context.cwd.clone() }; - match filter { - FilterMode::Global => &mut query, - FilterMode::Host => query.and_where_eq("hostname", quote(&context.hostname)), - FilterMode::Session => query.and_where_eq("session", quote(&context.session)), - FilterMode::Directory => query.and_where_eq("cwd", quote(&context.cwd)), - FilterMode::Workspace => query.and_where_like_left("cwd", git_root), - }; + for filter in filters { + match filter { + FilterMode::Global => &mut query, + FilterMode::Host => query.and_where_eq("hostname", quote(&context.hostname)), + FilterMode::Session => query.and_where_eq("session", quote(&context.session)), + FilterMode::Directory => query.and_where_eq("cwd", quote(&context.cwd)), + FilterMode::Workspace => query.and_where_like_left("cwd", &git_root), + }; + } if unique { query.and_where_eq( diff --git a/atuin/src/command/client/history.rs b/atuin/src/command/client/history.rs index 4178180c..7d4689f9 100644 --- a/atuin/src/command/client/history.rs +++ b/atuin/src/command/client/history.rs @@ -1,5 +1,4 @@ use std::{ - env, fmt::{self, Display}, io::{self, Write}, time::Duration, @@ -15,7 +14,10 @@ use atuin_client::{ encryption, history::{store::HistoryStore, History}, record::{self, sqlite_store::SqliteStore}, - settings::Settings, + settings::{ + FilterMode::{Directory, Global, Session}, + Settings, + }, }; #[cfg(feature = "sync")] @@ -349,37 +351,16 @@ impl Cmd { print0: bool, reverse: bool, ) -> Result<()> { - let session = if session { - Some(env::var("ATUIN_SESSION")?) - } else { - None - }; - let cwd = if cwd { - Some(utils::get_current_dir()) - } else { - None + let filters = match (session, cwd) { + (true, true) => [Session, Directory], + (true, false) => [Session, Global], + (false, true) => [Global, Directory], + (false, false) => [settings.filter_mode, Global], }; - let history = match (session, cwd) { - (None, None) => { - db.list(settings.filter_mode, &context, None, false, include_deleted) - .await? - } - (None, Some(cwd)) => { - let query = format!("select * from history where cwd = '{cwd}';"); - db.query_history(&query).await? - } - (Some(session), None) => { - let query = format!("select * from history where session = '{session}';"); - db.query_history(&query).await? - } - (Some(session), Some(cwd)) => { - let query = format!( - "select * from history where cwd = '{cwd}' and session = '{session}';", - ); - db.query_history(&query).await? - } - }; + let history = db + .list(&filters, &context, None, false, include_deleted) + .await?; print_list(&history, mode, format.as_deref(), print0, reverse); @@ -393,15 +374,7 @@ impl Cmd { ) -> Result<()> { println!("Importing all history.db data into records.db"); - let history = db - .list( - atuin_client::settings::FilterMode::Global, - &context, - None, - false, - true, - ) - .await?; + let history = db.list(&[], &context, None, false, true).await?; for i in history { println!("loaded {}", i.id); diff --git a/atuin/src/command/client/search/engines.rs b/atuin/src/command/client/search/engines.rs index ad84b6d7..105ce147 100644 --- a/atuin/src/command/client/search/engines.rs +++ b/atuin/src/command/client/search/engines.rs @@ -35,7 +35,7 @@ pub trait SearchEngine: Send + Sync + 'static { async fn query(&mut self, state: &SearchState, db: &mut dyn Database) -> Result> { if state.input.as_str().is_empty() { Ok(db - .list(state.filter_mode, &state.context, Some(200), true, false) + .list(&[state.filter_mode], &state.context, Some(200), true, false) .await? .into_iter() .collect::>()) diff --git a/atuin/src/command/client/stats.rs b/atuin/src/command/client/stats.rs index e990b70b..969ab1ae 100644 --- a/atuin/src/command/client/stats.rs +++ b/atuin/src/command/client/stats.rs @@ -9,7 +9,7 @@ use interim::parse_date_string; use atuin_client::{ database::{current_context, Database}, history::History, - settings::{FilterMode, Settings}, + settings::Settings, }; use time::{Duration, OffsetDateTime, Time}; @@ -92,8 +92,7 @@ impl Cmd { let last_night = now.replace_time(Time::MIDNIGHT); let history = if words.as_str() == "all" { - db.list(FilterMode::Global, &context, None, false, false) - .await? + db.list(&[], &context, None, false, false).await? } else if words.trim() == "today" { let start = last_night; let end = start + Duration::days(1);