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:
@@ -224,7 +224,7 @@ in
|
|||||||
};
|
};
|
||||||
maxHistoryEntries = lib.mkOption {
|
maxHistoryEntries = lib.mkOption {
|
||||||
type = lib.types.int;
|
type = lib.types.int;
|
||||||
default = 1000;
|
default = 10000;
|
||||||
description = "The maximum number of entries to keep in the command history";
|
description = "The maximum number of entries to keep in the command history";
|
||||||
};
|
};
|
||||||
interactiveComments = lib.mkOption {
|
interactiveComments = lib.mkOption {
|
||||||
|
|||||||
@@ -217,12 +217,13 @@ impl History {
|
|||||||
format!("{home}/.shed_history")
|
format!("{home}/.shed_history")
|
||||||
}));
|
}));
|
||||||
let mut entries = read_hist_file(&path)?;
|
let mut entries = read_hist_file(&path)?;
|
||||||
// Enforce max_hist limit on loaded entries
|
// Enforce max_hist limit on loaded entries (negative = unlimited)
|
||||||
if entries.len() > max_hist {
|
if max_hist >= 0 && entries.len() > max_hist as usize {
|
||||||
entries = entries.split_off(entries.len() - max_hist);
|
entries = entries.split_off(entries.len() - max_hist as usize);
|
||||||
}
|
}
|
||||||
let search_mask = dedupe_entries(&entries);
|
let search_mask = dedupe_entries(&entries);
|
||||||
let cursor = search_mask.len();
|
let cursor = search_mask.len();
|
||||||
|
let max_size = if max_hist < 0 { None } else { Some(max_hist as u32) };
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
path,
|
path,
|
||||||
entries,
|
entries,
|
||||||
@@ -233,7 +234,7 @@ impl History {
|
|||||||
cursor,
|
cursor,
|
||||||
//search_direction: Direction::Backward,
|
//search_direction: Direction::Backward,
|
||||||
ignore_dups,
|
ignore_dups,
|
||||||
max_size: Some(max_hist as u32),
|
max_size,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
10
src/shopt.rs
10
src/shopt.rs
@@ -140,7 +140,7 @@ pub struct ShOptCore {
|
|||||||
pub dotglob: bool,
|
pub dotglob: bool,
|
||||||
pub autocd: bool,
|
pub autocd: bool,
|
||||||
pub hist_ignore_dupes: bool,
|
pub hist_ignore_dupes: bool,
|
||||||
pub max_hist: usize,
|
pub max_hist: isize,
|
||||||
pub interactive_comments: bool,
|
pub interactive_comments: bool,
|
||||||
pub auto_hist: bool,
|
pub auto_hist: bool,
|
||||||
pub bell_enabled: bool,
|
pub bell_enabled: bool,
|
||||||
@@ -178,10 +178,10 @@ impl ShOptCore {
|
|||||||
self.hist_ignore_dupes = val;
|
self.hist_ignore_dupes = val;
|
||||||
}
|
}
|
||||||
"max_hist" => {
|
"max_hist" => {
|
||||||
let Ok(val) = val.parse::<usize>() else {
|
let Ok(val) = val.parse::<isize>() else {
|
||||||
return Err(ShErr::simple(
|
return Err(ShErr::simple(
|
||||||
ShErrKind::SyntaxErr,
|
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;
|
self.max_hist = val;
|
||||||
@@ -256,7 +256,7 @@ impl ShOptCore {
|
|||||||
}
|
}
|
||||||
"max_hist" => {
|
"max_hist" => {
|
||||||
let mut output = String::from(
|
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));
|
output.push_str(&format!("{}", self.max_hist));
|
||||||
Ok(Some(output))
|
Ok(Some(output))
|
||||||
@@ -318,7 +318,7 @@ impl Default for ShOptCore {
|
|||||||
dotglob: false,
|
dotglob: false,
|
||||||
autocd: false,
|
autocd: false,
|
||||||
hist_ignore_dupes: true,
|
hist_ignore_dupes: true,
|
||||||
max_hist: 1000,
|
max_hist: 10_000,
|
||||||
interactive_comments: true,
|
interactive_comments: true,
|
||||||
auto_hist: true,
|
auto_hist: true,
|
||||||
bell_enabled: true,
|
bell_enabled: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user