mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 09:51:57 -05:00
Shell: Add "history" command that shows command history.
This commit is contained in:
parent
ba7364b43b
commit
16a5a76445
1 changed files with 13 additions and 1 deletions
|
@ -19,6 +19,7 @@
|
|||
//#define SH_DEBUG
|
||||
|
||||
GlobalState g;
|
||||
static LineEditor editor;
|
||||
|
||||
static void prompt()
|
||||
{
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -387,7 +400,6 @@ int main(int argc, char** argv)
|
|||
free(cwd);
|
||||
}
|
||||
|
||||
LineEditor editor;
|
||||
for (;;) {
|
||||
prompt();
|
||||
auto line = editor.get_line();
|
||||
|
|
Loading…
Add table
Reference in a new issue