From b92ef57d9cfb3b8b51848d3a2940b0b2251c0529 Mon Sep 17 00:00:00 2001 From: Lucas Faria Mendes Date: Fri, 5 Dec 2025 05:40:08 -0300 Subject: codecrafters submit [skip ci] --- src/shell.zig | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/shell.zig') diff --git a/src/shell.zig b/src/shell.zig index fd72288..5a848af 100644 --- a/src/shell.zig +++ b/src/shell.zig @@ -24,7 +24,7 @@ pub fn executeCommand( if (std.mem.eql(u8, cmd_name, "exit")) return builtins.executeExit(); if (std.mem.eql(u8, cmd_name, "history")) { - // Check if args contain -r flag for reading from file + // Check if args contain -r or -w flag for reading/writing file if (args) |a| { const trimmed = std.mem.trim(u8, a, " "); if (std.mem.startsWith(u8, trimmed, "-r ")) { @@ -33,6 +33,12 @@ pub fn executeCommand( try builtins.executeHistoryRead(allocator, stdout, file_path, history); } return .continue_loop; + } else if (std.mem.startsWith(u8, trimmed, "-w ")) { + const file_path = std.mem.trim(u8, trimmed[3..], " "); + if (file_path.len > 0) { + try builtins.executeHistoryWrite(stdout, file_path, history.items); + } + return .continue_loop; } } -- cgit v1.2.3