mirror of
https://git.checksum.fail/alec/erythros
synced 2025-12-10 13:09:55 +02:00
System/Shell/Commands: Add cd
This commit is contained in:
21
System/Shell/Commands/cd.HC
Normal file
21
System/Shell/Commands/cd.HC
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user