summaryrefslogtreecommitdiffstats
path: root/src/hci/shell.c
diff options
context:
space:
mode:
authorMichael Brown2011-03-30 20:44:15 +0200
committerMichael Brown2011-03-30 20:44:15 +0200
commitde2d983ab85b383d3d35cf0fb0a85f28835b09f6 (patch)
treee6dd76378c279dbacecb60a268924b39930849c6 /src/hci/shell.c
parent[readline] Add history support (diff)
downloadipxe-de2d983ab85b383d3d35cf0fb0a85f28835b09f6.tar.gz
ipxe-de2d983ab85b383d3d35cf0fb0a85f28835b09f6.tar.xz
ipxe-de2d983ab85b383d3d35cf0fb0a85f28835b09f6.zip
[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>
Diffstat (limited to 'src/hci/shell.c')
-rw-r--r--src/hci/shell.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/hci/shell.c b/src/hci/shell.c
index f8b1ec27..e426ba94 100644
--- a/src/hci/shell.c
+++ b/src/hci/shell.c
@@ -21,6 +21,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
+#include <string.h>
#include <getopt.h>
#include <readline/readline.h>
#include <ipxe/command.h>
@@ -75,17 +76,25 @@ struct command help_command __command = {
*
*/
int shell ( void ) {
+ struct readline_history history;
char *line;
int rc = 0;
+ /* Initialise shell history */
+ memset ( &history, 0, sizeof ( history ) );
+
+ /* Read and execute commands */
do {
- line = readline ( shell_prompt );
+ line = readline_history ( shell_prompt, &history );
if ( line ) {
rc = system ( line );
free ( line );
}
} while ( ! shell_stopped ( SHELL_STOP_COMMAND_SEQUENCE ) );
+ /* Discard shell history */
+ history_free ( &history );
+
return rc;
}