diff options
| author | Tom Cammann <cammann.tom@gmail.com> | 2023-04-11 09:39:23 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-11 09:39:23 +0100 |
| commit | e149a0a6e9747b238032321f5e1554d0d8ded118 (patch) | |
| tree | 06c3e33912d6e3208b3931db77df02d5bebed4d8 /atuin-client/src | |
| parent | Atuin stats with day, month, week and year filter (#858) (diff) | |
| download | atuin-e149a0a6e9747b238032321f5e1554d0d8ded118.zip | |
Add `--reverse` to `atuin search` (#862)
Add `-r/--reverse` flag to `atuin search` to allow searching by oldest
results first.
Example to find the oldest `cargo` command:
```
atuin search --limit 1 --reverse cargo
```
Diffstat (limited to 'atuin-client/src')
| -rw-r--r-- | atuin-client/src/database.rs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/atuin-client/src/database.rs b/atuin-client/src/database.rs index 6d364dbe..c4a9ddc3 100644 --- a/atuin-client/src/database.rs +++ b/atuin-client/src/database.rs @@ -35,6 +35,7 @@ pub struct OptFilters { pub after: Option<String>, pub limit: Option<i64>, pub offset: Option<i64>, + pub reverse: bool, } pub fn current_context() -> Context { @@ -354,9 +355,7 @@ impl Database for Sqlite { ) -> Result<Vec<History>> { let mut sql = SqlBuilder::select_from("history"); - sql.group_by("command") - .having("max(timestamp)") - .order_desc("timestamp"); + sql.group_by("command").having("max(timestamp)"); if let Some(limit) = filter_options.limit { sql.limit(limit); @@ -366,6 +365,12 @@ impl Database for Sqlite { sql.offset(offset); } + if filter_options.reverse { + sql.order_asc("timestamp"); + } else { + sql.order_desc("timestamp"); + } + match filter { FilterMode::Global => &mut sql, FilterMode::Host => sql.and_where_eq("hostname", quote(&context.hostname)), |
