mirror of
https://github.com/ipxe/ipxe
synced 2025-12-11 22:11:08 +03:00
[cmdline] Add support for shell history
The up and down arrow keys will now function roughly as expected at the iPXE command line. Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -21,6 +21,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <readline/readline.h>
|
#include <readline/readline.h>
|
||||||
#include <ipxe/command.h>
|
#include <ipxe/command.h>
|
||||||
@@ -75,17 +76,25 @@ struct command help_command __command = {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
int shell ( void ) {
|
int shell ( void ) {
|
||||||
|
struct readline_history history;
|
||||||
char *line;
|
char *line;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
|
/* Initialise shell history */
|
||||||
|
memset ( &history, 0, sizeof ( history ) );
|
||||||
|
|
||||||
|
/* Read and execute commands */
|
||||||
do {
|
do {
|
||||||
line = readline ( shell_prompt );
|
line = readline_history ( shell_prompt, &history );
|
||||||
if ( line ) {
|
if ( line ) {
|
||||||
rc = system ( line );
|
rc = system ( line );
|
||||||
free ( line );
|
free ( line );
|
||||||
}
|
}
|
||||||
} while ( ! shell_stopped ( SHELL_STOP_COMMAND_SEQUENCE ) );
|
} while ( ! shell_stopped ( SHELL_STOP_COMMAND_SEQUENCE ) );
|
||||||
|
|
||||||
|
/* Discard shell history */
|
||||||
|
history_free ( &history );
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user