From 1efaf0e516697069525b4ba6a0bc83d5ae444b51 Mon Sep 17 00:00:00 2001 From: pagedmov Date: Thu, 5 Mar 2026 09:34:02 -0500 Subject: [PATCH] updated max_hist default to 10,000 and added an option to remove the cap by setting it to -1 --- nix/hm-module.nix | 2 +- src/readline/history.rs | 9 +++++---- src/shopt.rs | 10 +++++----- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/nix/hm-module.nix b/nix/hm-module.nix index b45d333..4ccfcb0 100644 --- a/nix/hm-module.nix +++ b/nix/hm-module.nix @@ -224,7 +224,7 @@ in }; maxHistoryEntries = lib.mkOption { type = lib.types.int; - default = 1000; + default = 10000; description = "The maximum number of entries to keep in the command history"; }; interactiveComments = lib.mkOption { diff --git a/src/readline/history.rs b/src/readline/history.rs index 6d18e34..75d6369 100644 --- a/src/readline/history.rs +++ b/src/readline/history.rs @@ -217,12 +217,13 @@ impl History { format!("{home}/.shed_history") })); let mut entries = read_hist_file(&path)?; - // Enforce max_hist limit on loaded entries - if entries.len() > max_hist { - entries = entries.split_off(entries.len() - max_hist); + // Enforce max_hist limit on loaded entries (negative = unlimited) + if max_hist >= 0 && entries.len() > max_hist as usize { + entries = entries.split_off(entries.len() - max_hist as usize); } let search_mask = dedupe_entries(&entries); let cursor = search_mask.len(); + let max_size = if max_hist < 0 { None } else { Some(max_hist as u32) }; Ok(Self { path, entries, @@ -233,7 +234,7 @@ impl History { cursor, //search_direction: Direction::Backward, ignore_dups, - max_size: Some(max_hist as u32), + max_size, }) } diff --git a/src/shopt.rs b/src/shopt.rs index be49352..bb0df48 100644 --- a/src/shopt.rs +++ b/src/shopt.rs @@ -140,7 +140,7 @@ pub struct ShOptCore { pub dotglob: bool, pub autocd: bool, pub hist_ignore_dupes: bool, - pub max_hist: usize, + pub max_hist: isize, pub interactive_comments: bool, pub auto_hist: bool, pub bell_enabled: bool, @@ -178,10 +178,10 @@ impl ShOptCore { self.hist_ignore_dupes = val; } "max_hist" => { - let Ok(val) = val.parse::() else { + let Ok(val) = val.parse::() else { return Err(ShErr::simple( ShErrKind::SyntaxErr, - "shopt: expected a positive integer for max_hist value", + "shopt: expected an integer for max_hist value (-1 for unlimited)", )); }; self.max_hist = val; @@ -256,7 +256,7 @@ impl ShOptCore { } "max_hist" => { let mut output = String::from( - "Maximum number of entries in the command history file (default '.shedhist')\n", + "Maximum number of entries in the command history file (-1 for unlimited)\n", ); output.push_str(&format!("{}", self.max_hist)); Ok(Some(output)) @@ -318,7 +318,7 @@ impl Default for ShOptCore { dotglob: false, autocd: false, hist_ignore_dupes: true, - max_hist: 1000, + max_hist: 10_000, interactive_comments: true, auto_hist: true, bell_enabled: true,