diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/builtins.zig | 8 | ||||
| -rw-r--r-- | src/shell.zig | 5 |
2 files changed, 12 insertions, 1 deletions
diff --git a/src/builtins.zig b/src/builtins.zig index c989a35..ea34f19 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -1,7 +1,7 @@ const std = @import("std"); const path = @import("path.zig"); -const BUILTINS = [_][]const u8{ "exit", "echo", "type" }; +const BUILTINS = [_][]const u8{ "exit", "echo", "type", "pwd" }; pub const CommandResult = enum { continue_loop, @@ -27,6 +27,12 @@ pub fn executeEcho(stdout: anytype, args: ?[]const u8) !void { } } +pub fn executePwd(allocator: std.mem.Allocator, stdout: anytype) !void { + const cwd = try std.fs.cwd().realpathAlloc(allocator, "."); + defer allocator.free(cwd); + try stdout.print("{s}\n", .{cwd}); +} + pub fn executeType(allocator: std.mem.Allocator, stdout: anytype, args: ?[]const u8) !void { if (args) |a| { if (isBuiltin(a)) { diff --git a/src/shell.zig b/src/shell.zig index c5aded1..2494fda 100644 --- a/src/shell.zig +++ b/src/shell.zig @@ -17,6 +17,11 @@ pub fn executeCommand( return .continue_loop; } + if (std.mem.eql(u8, cmd_name, "pwd")) { + try builtins.executePwd(allocator, stdout); + return .continue_loop; + } + if (std.mem.eql(u8, cmd_name, "type")) { try builtins.executeType(allocator, stdout, args); return .continue_loop; |