Skip to content

Commit

Permalink
Add --offset flag to atuin search
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
takac committed Mar 28, 2023
1 parent 0f13904 commit 6356327
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions atuin-client/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub struct OptFilters {
pub before: Option<String>,
pub after: Option<String>,
pub limit: Option<i64>,
pub offset: Option<i64>,
}

pub fn current_context() -> Context {
Expand Down Expand Up @@ -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)),
Expand Down
5 changes: 5 additions & 0 deletions src/command/client/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ pub struct Cmd {
#[arg(long)]
limit: Option<i64>,

/// Offset from the start of the results
#[arg(long)]
offset: Option<i64>,

/// Open interactive search UI
#[arg(long, short)]
interactive: bool,
Expand Down Expand Up @@ -111,6 +115,7 @@ impl Cmd {
before: self.before,
after: self.after,
limit: self.limit,
offset: self.offset,
};

let mut entries =
Expand Down

0 comments on commit 6356327

Please sign in to comment.