aboutsummaryrefslogtreecommitdiffstats
path: root/crates/client/src/atuin_history
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2026-07-20 17:54:34 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2026-07-20 17:54:34 +0200
commit6bd2b80be51a8623640fbd77afa1da09289e40cc (patch)
tree8fa76fc78e27a4f3d6f57af07805a83e9877f0ad /crates/client/src/atuin_history
parentchore: Commit (diff)
downloadatuin-6bd2b80be51a8623640fbd77afa1da09289e40cc.zip
chore: All compiles
Diffstat (limited to 'crates/client/src/atuin_history')
-rw-r--r--crates/client/src/atuin_history/mod.rs1
-rw-r--r--crates/client/src/atuin_history/sort.rs46
-rw-r--r--crates/client/src/atuin_history/stats.rs28
3 files changed, 3 insertions, 72 deletions
diff --git a/crates/client/src/atuin_history/mod.rs b/crates/client/src/atuin_history/mod.rs
index 41336a14..b3ca0d2f 100644
--- a/crates/client/src/atuin_history/mod.rs
+++ b/crates/client/src/atuin_history/mod.rs
@@ -1,2 +1 @@
-pub(crate) mod sort;
pub(crate) mod stats;
diff --git a/crates/client/src/atuin_history/sort.rs b/crates/client/src/atuin_history/sort.rs
deleted file mode 100644
index 3143fa68..00000000
--- a/crates/client/src/atuin_history/sort.rs
+++ /dev/null
@@ -1,46 +0,0 @@
-use crate::atuin_client::history::History;
-
-type ScoredHistory = (f64, History);
-
-// Fuzzy search already comes sorted by minspan
-// This sorting should be applicable to all search modes, and solve the more "obvious" issues
-// first.
-// Later on, we can pass in context and do some boosts there too.
-pub(crate) fn sort(query: &str, input: Vec<History>) -> Vec<History> {
- // This can totally be extended. We need to be _careful_ that it's not slow.
- // We also need to balance sorting db-side with sorting here. SQLite can do a lot,
- // but some things are just much easier/more doable in Rust.
-
- let mut scored = input
- .into_iter()
- .map(|h| {
- // If history is _prefixed_ with the query, score it more highly
- let score = if h.command.starts_with(query) {
- 2.0
- } else if h.command.contains(query) {
- 1.75
- } else {
- 1.0
- };
-
- // calculate how long ago the history was, in seconds
- let now = time::OffsetDateTime::now_utc().unix_timestamp();
- let time = h.timestamp.unix_timestamp();
- let diff = std::cmp::max(1, now - time); // no /0 please
-
- // prefer newer history, but not hugely so as to offset the other scoring
- // the numbers will get super small over time, but I don't want time to overpower other
- // scoring
- #[expect(clippy::cast_precision_loss)]
- let time_score = 1.0 + (1.0 / diff as f64);
- let score = score * time_score;
-
- (score, h)
- })
- .collect::<Vec<ScoredHistory>>();
-
- scored.sort_by(|a, b| a.0.partial_cmp(&b.0).unwrap().reverse());
-
- // Remove the scores and return the history
- scored.into_iter().map(|(_, h)| h).collect::<Vec<History>>()
-}
diff --git a/crates/client/src/atuin_history/stats.rs b/crates/client/src/atuin_history/stats.rs
index c53dafb2..462fe077 100644
--- a/crates/client/src/atuin_history/stats.rs
+++ b/crates/client/src/atuin_history/stats.rs
@@ -2,9 +2,10 @@ use std::collections::{HashMap, HashSet};
use crossterm::style::{Color, ResetColor, SetAttribute, SetForegroundColor};
use serde::{Deserialize, Serialize};
+use turtle_daemon::aclient::history::History;
use unicode_segmentation::UnicodeSegmentation;
-use crate::atuin_client::{history::History, settings::Settings};
+use crate::atuin_client::settings::Settings;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub(crate) struct Stats {
@@ -278,9 +279,9 @@ pub(crate) fn compute(
#[cfg(test)]
mod tests {
- use crate::atuin_client::history::History;
use crate::atuin_client::settings::Settings;
use time::OffsetDateTime;
+ use turtle_daemon::aclient::history::History;
use super::compute;
use super::{interesting_command, split_at_pipe, strip_leading_env_vars};
@@ -301,29 +302,6 @@ mod tests {
}
#[test]
- fn ignored_commands() {
- let mut settings = Settings::new().unwrap();
- settings.stats.ignored_commands.push("cd".to_string());
-
- let history = [
- History::import()
- .timestamp(OffsetDateTime::now_utc())
- .command("cd foo")
- .build()
- .into(),
- History::import()
- .timestamp(OffsetDateTime::now_utc())
- .command("cargo build stuff")
- .build()
- .into(),
- ];
-
- let stats = compute(&settings, &history, 10, 1).expect("failed to compute stats");
- assert_eq!(stats.total_commands, 1);
- assert_eq!(stats.unique_commands, 1);
- }
-
- #[test]
fn interesting_commands() {
let settings = Settings::new().unwrap();