Skip to content

Commit

Permalink
Shell: Fixed pushd and popd
Browse files Browse the repository at this point in the history
Fixed a few issues with both `pushd` and `popd`. There was a few
typos etcetera causing it to behave errantly in certain situations.
  • Loading branch information
Quaker762 authored and awesomekling committed Sep 15, 2019
1 parent 77d6dbc commit 2976e88
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions Shell/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -247,13 +246,16 @@ static int sh_pushd(int argc, char** argv)

// Let's assume the user's typed in 'pushd <dir>'
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] != '-') {
Expand All @@ -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);
Expand Down

0 comments on commit 2976e88

Please sign in to comment.