From 76a2c6e44dd5b7852eea3b9f24cae0fd6c0aac68 Mon Sep 17 00:00:00 2001 From: AnotherTest Date: Mon, 26 Oct 2020 02:37:43 +0330 Subject: [PATCH] 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. --- Shell/Builtin.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Shell/Builtin.cpp b/Shell/Builtin.cpp index 73550e2d4a..44a1d8852e 100644 --- a/Shell/Builtin.cpp +++ b/Shell/Builtin.cpp @@ -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);