summaryrefslogtreecommitdiff
path: root/src/shell.zig
diff options
context:
space:
mode:
authorLucas Faria Mendes <lucas.oliveira1676@etec.sp.gov.br>2025-12-05 08:46:32 +0000
committerLucas Faria Mendes <lucas.oliveira1676@etec.sp.gov.br>2025-12-05 08:46:32 +0000
commit8a2b0d1ccca3a5d0f50b4db1b84687000dc74882 (patch)
tree91ff883308422aa65900374bd23e3347406a804b /src/shell.zig
parentb92ef57d9cfb3b8b51848d3a2940b0b2251c0529 (diff)
downloadshell-zig-8a2b0d1ccca3a5d0f50b4db1b84687000dc74882.tar.gz
shell-zig-8a2b0d1ccca3a5d0f50b4db1b84687000dc74882.zip
codecrafters submit [skip ci]
Diffstat (limited to 'src/shell.zig')
-rw-r--r--src/shell.zig9
1 files changed, 8 insertions, 1 deletions
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;
}
}