summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.zig21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/main.zig b/src/main.zig
index 1511740..92067a4 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -26,6 +26,16 @@ fn parseCommand(input: []const u8) struct { name: []const u8, args: ?[]const u8
};
}
+fn isBuiltin(cmd_name: []const u8) bool {
+ const builtins = [_][]const u8{ "exit", "echo", "type" };
+ for (builtins) |builtin| {
+ if (std.mem.eql(u8, cmd_name, builtin)) {
+ return true;
+ }
+ }
+ return false;
+}
+
fn executeCommand(cmd_name: []const u8, args: ?[]const u8) !CommandResult {
if (std.mem.eql(u8, cmd_name, "exit")) {
return .exit_shell;
@@ -40,6 +50,17 @@ fn executeCommand(cmd_name: []const u8, args: ?[]const u8) !CommandResult {
return .continue_loop;
}
+ if (std.mem.eql(u8, cmd_name, "type")) {
+ if (args) |a| {
+ if (isBuiltin(a)) {
+ try stdout.print("{s} is a shell builtin\n", .{a});
+ } else {
+ try stdout.print("{s}: not found\n", .{a});
+ }
+ }
+ return .continue_loop;
+ }
+
// Command not found
try stdout.print("{s}: command not found\n", .{cmd_name});
return .continue_loop;