21 lines
516 B
Zig
21 lines
516 B
Zig
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);
|
||
|
|
}
|