diff options
| author | Lucas Faria Mendes <lucas.oliveira1676@etec.sp.gov.br> | 2025-12-05 08:36:01 +0000 |
|---|---|---|
| committer | Lucas Faria Mendes <lucas.oliveira1676@etec.sp.gov.br> | 2025-12-05 08:36:01 +0000 |
| commit | 379cdbd946dfb035e61f96653db618cba4906864 (patch) | |
| tree | 1245beeb246dafc67c6c407d52f1277f1b7042d2 /src/shell.zig | |
| parent | 440715dc1d137de062b5787666689fbd586a5881 (diff) | |
| download | shell-zig-379cdbd946dfb035e61f96653db618cba4906864.tar.gz shell-zig-379cdbd946dfb035e61f96653db618cba4906864.zip | |
codecrafters submit [skip ci]
Diffstat (limited to 'src/shell.zig')
| -rw-r--r-- | src/shell.zig | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/shell.zig b/src/shell.zig index bd50ff1..fd72288 100644 --- a/src/shell.zig +++ b/src/shell.zig @@ -19,12 +19,24 @@ pub fn executeCommand( error_redirect: ?[]const u8, append_output: ?[]const u8, append_error: ?[]const u8, - history_list: []const []const u8, + history: *std.ArrayList([]const u8), ) !builtins.CommandResult { if (std.mem.eql(u8, cmd_name, "exit")) return builtins.executeExit(); if (std.mem.eql(u8, cmd_name, "history")) { - try builtins.executeHistory(stdout, history_list, args); + // Check if args contain -r flag for reading from file + if (args) |a| { + const trimmed = std.mem.trim(u8, a, " "); + if (std.mem.startsWith(u8, trimmed, "-r ")) { + const file_path = std.mem.trim(u8, trimmed[3..], " "); + if (file_path.len > 0) { + try builtins.executeHistoryRead(allocator, stdout, file_path, history); + } + return .continue_loop; + } + } + + try builtins.executeHistory(stdout, history.items, args); return .continue_loop; } |