Files
xsh/src/builtin/cmds/cd.zig
T

21 lines
516 B
Zig
Raw Normal View History

2026-08-23 11:11:36 +03:00
const std = @import("std");
pub fn execute(
io: std.Io,
environ: *const std.process.Environ.Map,
argv: []const []const u8,
) !void {
const path = if (argv.len >= 2)
argv[1]
else
environ.get("USERPROFILE") orelse environ.get("HOME") orelse {
std.debug.print("xsh: cd: cannot find home directory\n", .{});
return;
};
var dir = try std.Io.Dir.cwd().openDir(io, path, .{});
defer dir.close(io);
try std.process.setCurrentDir(io, dir);
}