From 8a2b0d1ccca3a5d0f50b4db1b84687000dc74882 Mon Sep 17 00:00:00 2001 From: Lucas Faria Mendes Date: Fri, 5 Dec 2025 05:46:32 -0300 Subject: codecrafters submit [skip ci] --- src/shell.zig | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/shell.zig') diff --git a/src/shell.zig b/src/shell.zig index 5a848af..d3f75ec 100644 --- a/src/shell.zig +++ b/src/shell.zig @@ -20,11 +20,12 @@ pub fn executeCommand( append_output: ?[]const u8, append_error: ?[]const u8, history: *std.ArrayList([]const u8), + last_written_index: *usize, ) !builtins.CommandResult { if (std.mem.eql(u8, cmd_name, "exit")) return builtins.executeExit(); if (std.mem.eql(u8, cmd_name, "history")) { - // Check if args contain -r or -w flag for reading/writing file + // Check if args contain -r, -w, or -a flag for reading/writing/appending file if (args) |a| { const trimmed = std.mem.trim(u8, a, " "); if (std.mem.startsWith(u8, trimmed, "-r ")) { @@ -39,6 +40,12 @@ pub fn executeCommand( try builtins.executeHistoryWrite(stdout, file_path, history.items); } return .continue_loop; + } else if (std.mem.startsWith(u8, trimmed, "-a ")) { + const file_path = std.mem.trim(u8, trimmed[3..], " "); + if (file_path.len > 0) { + try builtins.executeHistoryAppend(stdout, file_path, history.items, last_written_index); + } + return .continue_loop; } } -- cgit v1.2.3