Shell: Fix cd' history (and cdh')

Previously, `cd` would push relative paths (and possibly nonexistent
ones too) into its history, so `cdh' would fail everywhere else.
This commit is contained in:
AnotherTest 2020-10-26 02:37:43 +03:30 committed by Andreas Kling
parent 6d7b01a3cf
commit 76a2c6e44d
Notes: sideshowbarker 2024-07-19 01:42:28 +09:00

View file

@ -127,11 +127,7 @@ int Shell::builtin_cd(int argc, const char** argv)
if (!arg_path) {
new_path = home;
if (cd_history.is_empty() || cd_history.last() != home)
cd_history.enqueue(home);
} else {
if (cd_history.is_empty() || cd_history.last() != arg_path)
cd_history.enqueue(arg_path);
if (strcmp(arg_path, "-") == 0) {
char* oldpwd = getenv("OLDPWD");
if (oldpwd == nullptr)
@ -153,6 +149,10 @@ int Shell::builtin_cd(int argc, const char** argv)
fprintf(stderr, "Invalid path '%s'\n", new_path.characters());
return 1;
}
if (cd_history.is_empty() || cd_history.last() != real_path)
cd_history.enqueue(real_path);
const char* path = real_path.characters();
int rc = chdir(path);