diff --git a/System/Shell/Commands/cd.HC b/System/Shell/Commands/cd.HC new file mode 100644 index 0000000..7566939 --- /dev/null +++ b/System/Shell/Commands/cd.HC @@ -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; +} \ No newline at end of file