summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLucas Faria Mendes <lucas.oliveira1676@etec.sp.gov.br>2025-12-05 08:52:03 +0000
committerLucas Faria Mendes <lucas.oliveira1676@etec.sp.gov.br>2025-12-05 08:52:03 +0000
commit45342f7c098d0f89726111f99404bc6ac6613609 (patch)
treee55fbcf447a52dcd1afa2c139736e8cad601018a /src
parent84de37f25e24f68424e0060de28920bb6a841595 (diff)
downloadshell-zig-45342f7c098d0f89726111f99404bc6ac6613609.tar.gz
shell-zig-45342f7c098d0f89726111f99404bc6ac6613609.zip
codecrafters submit [skip ci]
Diffstat (limited to 'src')
-rw-r--r--src/main.zig13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/main.zig b/src/main.zig
index cc272ec..560ae60 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -456,4 +456,17 @@ pub fn main() !void {
break;
}
}
+
+ // Save history to HISTFILE on exit
+ if (std.posix.getenv("HISTFILE")) |histfile_path| {
+ const file = std.fs.cwd().createFile(histfile_path, .{}) catch null;
+ if (file) |f| {
+ defer f.close();
+
+ for (history.items) |cmd| {
+ _ = f.writeAll(cmd) catch {};
+ _ = f.writeAll("\n") catch {};
+ }
+ }
+ }
}