load static method
Loads the history for key, returning an empty history when no file
exists yet. Pass home to override the base directory (used by tests).
Implementation
static Future<CommandHistory> load({
required String key,
String? home,
int maxEntries = 1000,
}) async {
final file = File(_path(key, home));
var entries = <String>[];
try {
if (await file.exists()) {
entries = (await file.readAsLines())
.where((l) => l.trim().isNotEmpty)
.toList();
if (entries.length > maxEntries) {
entries = entries.sublist(entries.length - maxEntries);
}
}
} on Object {
// A corrupt or unreadable history file must never break the shell.
entries = <String>[];
}
return CommandHistory._(entries, file, maxEntries);
}