Initial commit

This commit is contained in:
2026-08-23 11:11:36 +03:00
commit 0548f8de26
97 changed files with 20841 additions and 0 deletions
+54
View File
@@ -0,0 +1,54 @@
const std = @import("std");
const parser = @import("../shell/parser.zig");
const cd = @import("cmds/cd.zig");
const echo = @import("cmds/echo.zig");
const exit = @import("cmds/exit.zig");
const pwd = @import("cmds/pwd.zig");
const run = @import("cmds/run.zig");
pub const Shell = struct {
running: bool = true,
interrupted: bool = false,
environ: *const std.process.Environ.Map,
};
pub fn execute(
io: std.Io,
allocator: std.mem.Allocator,
shell: *Shell,
command: parser.Command,
) !bool {
if (command.argv.len == 0)
return true;
const name = command.argv[0];
if (std.mem.eql(u8, name, "cd")) {
try cd.execute(io, shell.environ, command.argv);
return true;
}
if (std.mem.eql(u8, name, "pwd")) {
try pwd.execute(io, allocator);
return true;
}
if (std.mem.eql(u8, name, "run")) {
try run.execute(io, allocator, command.argv);
return true;
}
if (std.mem.eql(u8, name, "echo")) {
try echo.execute(io, command.argv);
return true;
}
if (std.mem.eql(u8, name, "exit")) {
exit.execute(&shell.running);
return true;
}
return false;
}