From fa0a1447a60a854f2997c9e1b9fd87bca871b1d9 Mon Sep 17 00:00:00 2001 From: Tom Cammann Date: Wed, 29 Mar 2023 09:27:14 +0100 Subject: [PATCH] Add `--offset` flag to `atuin search` (#825) This flag allows the user to continue searching at an offset. This is useful for building tools that use atuin to search for previous commands and return only one result. ``` atuin search --limit 1 atuin search --limit 1 --offset 1 atuin search --limit 1 --offset 2 ``` --- atuin-client/src/database.rs | 5 +++++ src/command/client/search.rs | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/atuin-client/src/database.rs b/atuin-client/src/database.rs index 1a577a7..6d364db 100644 --- a/atuin-client/src/database.rs +++ b/atuin-client/src/database.rs @@ -34,6 +34,7 @@ pub struct OptFilters { pub before: Option, pub after: Option, pub limit: Option, + pub offset: Option, } pub fn current_context() -> Context { @@ -361,6 +362,10 @@ impl Database for Sqlite { sql.limit(limit); } + if let Some(offset) = filter_options.offset { + sql.offset(offset); + } + match filter { FilterMode::Global => &mut sql, FilterMode::Host => sql.and_where_eq("hostname", quote(&context.hostname)), diff --git a/src/command/client/search.rs b/src/command/client/search.rs index 7a4d365..9d05fe5 100644 --- a/src/command/client/search.rs +++ b/src/command/client/search.rs @@ -49,6 +49,10 @@ pub struct Cmd { #[arg(long)] limit: Option, + /// Offset from the start of the results + #[arg(long)] + offset: Option, + /// Open interactive search UI #[arg(long, short)] interactive: bool, @@ -111,6 +115,7 @@ impl Cmd { before: self.before, after: self.after, limit: self.limit, + offset: self.offset, }; let mut entries =