From 2976e889e9ac229ddd98a2052f5f3eb11b901391 Mon Sep 17 00:00:00 2001 From: Jesse Buhagiar Date: Sun, 15 Sep 2019 23:55:02 +1000 Subject: [PATCH] Shell: Fixed `pushd` and `popd` Fixed a few issues with both `pushd` and `popd`. There was a few typos etcetera causing it to behave errantly in certain situations. --- Shell/main.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Shell/main.cpp b/Shell/main.cpp index dade25ad11..4abdc73165 100644 --- a/Shell/main.cpp +++ b/Shell/main.cpp @@ -175,7 +175,7 @@ static int sh_popd(int argc, char** argv) return 0; } - for (int i = 0; i < argc; i++) { + for (int i = 1; i < argc; i++) { const char* arg = argv[i]; if (!strcmp(arg, "-n")) { should_switch = false; @@ -189,7 +189,6 @@ static int sh_popd(int argc, char** argv) } const char* real_path = canonical_path.string().characters(); - g.directory_stack.append(g.cwd.characters()); struct stat st; int rc = stat(real_path, &st); @@ -247,13 +246,16 @@ static int sh_pushd(int argc, char** argv) // Let's assume the user's typed in 'pushd ' if (argc == 2) { + g.directory_stack.append(g.cwd.characters()); if (argv[1][0] == '/') { path_builder.append(argv[1]); } - else + else { path_builder.appendf("%s/%s", g.cwd.characters(), argv[1]); + } } else if (argc == 3) { - for (int i = 0; i < argc; i++) { + g.directory_stack.append(g.cwd.characters()); + for (int i = 1; i < argc; i++) { const char* arg = argv[i]; if (arg[0] != '-') { @@ -276,7 +278,6 @@ static int sh_pushd(int argc, char** argv) } const char* real_path = canonical_path.string().characters(); - g.directory_stack.append(real_path); struct stat st; int rc = stat(real_path, &st);