diff options
| author | Lucas Faria Mendes <lucas.oliveira1676@etec.sp.gov.br> | 2025-12-05 08:52:03 +0000 |
|---|---|---|
| committer | Lucas Faria Mendes <lucas.oliveira1676@etec.sp.gov.br> | 2025-12-05 08:52:03 +0000 |
| commit | 45342f7c098d0f89726111f99404bc6ac6613609 (patch) | |
| tree | e55fbcf447a52dcd1afa2c139736e8cad601018a /src/main.zig | |
| parent | 84de37f25e24f68424e0060de28920bb6a841595 (diff) | |
| download | shell-zig-45342f7c098d0f89726111f99404bc6ac6613609.tar.gz shell-zig-45342f7c098d0f89726111f99404bc6ac6613609.zip | |
codecrafters submit [skip ci]
Diffstat (limited to 'src/main.zig')
| -rw-r--r-- | src/main.zig | 13 |
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 {}; + } + } + } } |