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:
parent
6d7b01a3cf
commit
76a2c6e44d
Notes:
sideshowbarker
2024-07-19 01:42:28 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/76a2c6e44dd Pull-request: https://github.com/SerenityOS/serenity/pull/3852 Reviewed-by: https://github.com/asynts
1 changed files with 4 additions and 4 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue