Add sh(1) history builtin.
This commit is contained in:
parent
3c69791078
commit
c6af3bc074
14
sh/sh.c
14
sh/sh.c
|
@ -58,6 +58,7 @@ static const char* builtin_commands[] =
|
||||||
"exit",
|
"exit",
|
||||||
"unset",
|
"unset",
|
||||||
"clearenv",
|
"clearenv",
|
||||||
|
"history",
|
||||||
(const char*) NULL,
|
(const char*) NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1341,6 +1342,19 @@ struct execute_result execute(char** tokens,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( strcmp(argv[0], "history") == 0 )
|
||||||
|
{
|
||||||
|
for ( size_t i = 0; i < edit_state.history_used; i++ )
|
||||||
|
{
|
||||||
|
const char* line = edit_state.history[i];
|
||||||
|
if ( fprintf(stdout, "%5zu %s\n", i + 1, line) < 0 )
|
||||||
|
err(1, "stdout");
|
||||||
|
}
|
||||||
|
if ( fflush(stdout) == EOF )
|
||||||
|
err(1, "stdout");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
execvp(argv[0], argv);
|
execvp(argv[0], argv);
|
||||||
|
|
||||||
if ( interactive && errno == ENOENT )
|
if ( interactive && errno == ENOENT )
|
||||||
|
|
Loading…
Reference in New Issue