System/Shell/Commands: Add cd

This commit is contained in:
Alec Murphy
2025-09-20 10:31:14 -04:00
parent 682ca552d3
commit 5ecae8fc20

View File

@@ -0,0 +1,21 @@
I64 @shell_cmd_cd(@shell* sh, I64 argc, U8** argv)
{
I64 res = 0;
if (argc < 2) {
StrPrint(&sh->cwd, &Compositor.session.home);
return res;
}
U8* full_expanded_path = @shell_expand_relative_path(sh, argv[1]);
if (!FileSystem.PathExists(full_expanded_path)) {
Stdio.WriteLine(sh, "cd: %s: No such file or directory\n", argv[1]);
res = 1;
} else {
U8* new_path = @shell_expand_relative_path_to_root_path(sh, argv[1]);
U8* resolved_path = @filesystem_resolve_path(new_path);
StrPrint(&sh->cwd, resolved_path);
Free(resolved_path);
Free(new_path);
}
Free(full_expanded_path);
return res;
}