load static method

Future<CommandHistory> load({
  1. required String key,
  2. String? home,
  3. int maxEntries = 1000,
})

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));
  final buffer = CommandHistoryBuffer(maxEntries: maxEntries);
  try {
    if (await file.exists()) {
      buffer.replaceAll(
        (await file.readAsLines()).where((l) => l.trim().isNotEmpty),
      );
    }
  } on Object {
    // A corrupt or unreadable history file must never break the shell.
  }
  return CommandHistory._(buffer, file);
}