updated max_hist default to 10,000 and added an option to remove the cap by setting it to -1

This commit is contained in:
2026-03-05 09:34:02 -05:00
parent 30ada66cab
commit 1efaf0e516
3 changed files with 11 additions and 10 deletions

View File

@@ -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 {

View File

@@ -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,
})
}

View File

@@ -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::<usize>() else {
let Ok(val) = val.parse::<isize>() 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,