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