[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: PATCH: A new 'history' builtin for ash and hush
From: Flemming Madsen <busybox () themadsens ! dk>
Date: 2011-09-26 19:15:24
Message-ID: CACWu54UmTT067TYKq7=gipPswUaQJ9X7z5YbtG2AZJ=_TB7hkA () mail ! gmail ! com
[Download RAW message or body]
A new 'history' builtin for ash and hush to show what is remembered in the
command history.
Signed-off-by: Flemming Madsen <busybox@themadsens.dk>
---
["04-history-builtin-command.patch" (text/x-patch)]
A new 'history' builtin for ash and hush to show what is remembered in the
command history.
Signed-off-by: Flemming Madsen <busybox@themadsens.dk>
---
Index: busybox/busybox-1.19.2/include/libbb.h
===================================================================
--- busybox.orig/busybox-1.19.2/include/libbb.h 2011-09-20 19:46:14.000000000 +0200
+++ busybox/busybox-1.19.2/include/libbb.h 2011-09-20 20:07:35.000000000 +0200
@@ -1421,6 +1421,7 @@
# if MAX_HISTORY
int cnt_history;
int cur_history;
+ int cur_cmdno;
int max_history; /* must never be <= 0 */
# if ENABLE_FEATURE_EDITING_SAVEHISTORY
unsigned cnt_history_in_file;
Index: busybox/busybox-1.19.2/libbb/lineedit.c
===================================================================
--- busybox.orig/busybox-1.19.2/libbb/lineedit.c 2011-09-20 19:46:14.000000000 +0200
+++ busybox/busybox-1.19.2/libbb/lineedit.c 2011-09-20 20:07:35.000000000 +0200
@@ -2142,8 +2142,10 @@
#if MAX_HISTORY > 0
# if ENABLE_FEATURE_EDITING_SAVEHISTORY
if ((state->flags & SAVE_HISTORY) && state->hist_file)
- if (state->cnt_history == 0)
+ if (state->cnt_history == 0) {
load_history(state);
+ state->cur_cmdno = state->cnt_history;
+ }
# endif
if (state->flags & DO_HISTORY)
state->cur_history = state->cnt_history;
@@ -2612,8 +2614,10 @@
free(command_ps);
#endif
- if (command_len > 0)
+ if (command_len > 0) {
remember_in_history(command);
+ state->cur_cmdno++;
+ }
if (break_out > 0) {
command[command_len++] = '\n';
Index: busybox/busybox-1.19.2/shell/ash.c
===================================================================
--- busybox.orig/busybox-1.19.2/shell/ash.c 2011-09-20 19:46:14.000000000 +0200
+++ busybox/busybox-1.19.2/shell/ash.c 2011-09-20 20:07:33.000000000 +0200
@@ -9019,6 +9019,9 @@
#if !ENABLE_FEATURE_SH_EXTRA_QUIET
static int helpcmd(int, char **) FAST_FUNC;
#endif
+#if MAX_HISTORY
+static int historycmd(int, char **) FAST_FUNC;
+#endif
#if ENABLE_SH_MATH_SUPPORT
static int letcmd(int, char **) FAST_FUNC;
#endif
@@ -9092,6 +9095,9 @@
#if !ENABLE_FEATURE_SH_EXTRA_QUIET
{ BUILTIN_NOSPEC "help" , helpcmd },
#endif
+#if MAX_HISTORY
+ { BUILTIN_NOSPEC "history", historycmd },
+#endif
#if JOBS
{ BUILTIN_REGULAR "jobs" , jobscmd },
{ BUILTIN_REGULAR "kill" , killcmd },
@@ -12622,6 +12628,26 @@
}
#endif /* FEATURE_SH_EXTRA_QUIET */
+#if MAX_HISTORY
+/*
+ * Lists command history
+ */
+static int FAST_FUNC
+historycmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
+{
+ int i;
+ int n;
+
+ if (!line_input_state)
+ return EXIT_FAILURE;
+
+ n = line_input_state->cur_cmdno - line_input_state->cnt_history;
+ for (i = 0; i < line_input_state->cnt_history; i++, n++)
+ out1fmt("%4d %s\n", n, line_input_state->history[i]);
+ return EXIT_SUCCESS;
+}
+#endif
+
/*
* The export and readonly commands.
*/
Index: busybox/busybox-1.19.2/shell/hush.c
===================================================================
--- busybox.orig/busybox-1.19.2/shell/hush.c 2011-09-20 19:46:14.000000000 +0200
+++ busybox/busybox-1.19.2/shell/hush.c 2011-09-20 20:08:32.000000000 +0200
@@ -853,6 +853,9 @@
#if ENABLE_HUSH_HELP
static int builtin_help(char **argv) FAST_FUNC;
#endif
+#if MAX_HISTORY
+static int builtin_history(char **argv) FAST_FUNC;
+#endif
#if ENABLE_HUSH_LOCAL
static int builtin_local(char **argv) FAST_FUNC;
#endif
@@ -922,6 +925,9 @@
#if ENABLE_HUSH_HELP
BLTIN("help" , builtin_help , NULL),
#endif
+#if MAX_HISTORY
+ BLTIN("history" , builtin_history , "Show command history"),
+#endif
#if ENABLE_HUSH_JOB
BLTIN("jobs" , builtin_jobs , "List jobs"),
#endif
@@ -8646,6 +8652,25 @@
return EXIT_SUCCESS;
}
#endif
+
+#if MAX_HISTORY
+/*
+ * Lists command history
+ */
+static int FAST_FUNC builtin_history(char **argv UNUSED_PARAM)
+{
+ int i;
+ int n;
+
+ if (!G.line_input_state)
+ return EXIT_FAILURE;
+
+ n = G.line_input_state->cur_cmdno - G.line_input_state->cnt_history;
+ for (i = 0; i < G.line_input_state->cnt_history; i++, n++)
+ printf("%4d %s\n", n, G.line_input_state->history[i]);
+ return EXIT_SUCCESS;
+}
+#endif
#if ENABLE_HUSH_JOB
static int FAST_FUNC builtin_jobs(char **argv UNUSED_PARAM)
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic