From 2fba4aae933c17f0024110dd9ec4a57d748cf867 Mon Sep 17 00:00:00 2001 From: Ellie Huxtable Date: Thu, 18 Apr 2024 08:18:15 +0100 Subject: [PATCH] feat: allow ignoring failed commands (#1957) * feat: allow ignoring failed commands * cleanup --- atuin-client/src/settings.rs | 2 ++ atuin/src/command/client/history.rs | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/atuin-client/src/settings.rs b/atuin-client/src/settings.rs index 541cb4d9..035af321 100644 --- a/atuin-client/src/settings.rs +++ b/atuin-client/src/settings.rs @@ -370,6 +370,7 @@ pub struct Settings { pub scroll_context_lines: usize, pub history_format: String, pub prefers_reduced_motion: bool, + pub store_failed: bool, #[serde(with = "serde_regex", default = "RegexSet::empty")] pub history_filter: RegexSet, @@ -645,6 +646,7 @@ impl Settings { .set_default("keymap_mode_shell", "auto")? .set_default("keymap_cursor", HashMap::::new())? .set_default("smart_sort", false)? + .set_default("store_failed", true)? .set_default( "prefers_reduced_motion", std::env::var("NO_MOTION") diff --git a/atuin/src/command/client/history.rs b/atuin/src/command/client/history.rs index b9e54b50..e6774816 100644 --- a/atuin/src/command/client/history.rs +++ b/atuin/src/command/client/history.rs @@ -348,6 +348,15 @@ impl Cmd { return Ok(()); } + if !settings.store_failed && h.exit != 0 { + debug!("history has non-zero exit code, and store_failed is false"); + + // the history has already been inserted half complete. remove it + db.delete(h).await?; + + return Ok(()); + } + h.exit = exit; h.duration = match duration { Some(value) => i64::try_from(value).context("command took over 292 years")?,