Skip to content

Commit

Permalink
Shell: Add "history" command that shows command history.
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomekling committed May 6, 2019
1 parent ba7364b commit 16a5a76
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Shell/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
//#define SH_DEBUG

GlobalState g;
static LineEditor editor;

static void prompt()
{
Expand Down Expand Up @@ -112,6 +113,14 @@ static int sh_cd(int argc, char** argv)
return 0;
}

static int sh_history(int, char**)
{
for (int i = 0; i < editor.history().size(); ++i) {
printf("%6d %s\n", i, editor.history()[i].characters());
}
return 0;
}

static bool handle_builtin(int argc, char** argv, int& retval)
{
if (argc == 0)
Expand All @@ -132,6 +141,10 @@ static bool handle_builtin(int argc, char** argv, int& retval)
retval = sh_export(argc, argv);
return true;
}
if (!strcmp(argv[0], "history")) {
retval = sh_history(argc, argv);
return true;
}
return false;
}

Expand Down Expand Up @@ -387,7 +400,6 @@ int main(int argc, char** argv)
free(cwd);
}

LineEditor editor;
for (;;) {
prompt();
auto line = editor.get_line();
Expand Down

0 comments on commit 16a5a76

Please sign in to comment.