summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorarmink <[email protected]>2017-10-13 10:21:40 +0800
committerarmink <[email protected]>2017-10-13 10:21:40 +0800
commitc123451585d9869a96c86b2e5c2c718f515e4943 (patch)
tree75eb69a0d5509a4d9b5d6c71b3c802c369d2155e
parentdb88c0b6a23fa6d56094b6d6f5e9c3e577e9a88d (diff)
[Finsh] Stop push new history when current cmd is same as last cmd.
-rw-r--r--components/finsh/shell.c37
1 files changed, 23 insertions, 14 deletions
diff --git a/components/finsh/shell.c b/components/finsh/shell.c
index 3a1b66fd3f..d9ec4f6839 100644
--- a/components/finsh/shell.c
+++ b/components/finsh/shell.c
@@ -372,26 +372,35 @@ static void shell_push_history(struct finsh_shell *shell)
/* push history */
if (shell->history_count >= FINSH_HISTORY_LINES)
{
- /* move history */
- int index;
- for (index = 0; index < FINSH_HISTORY_LINES - 1; index ++)
+ /* if current cmd is same as last cmd, don't push */
+ if (memcmp(&shell->cmd_history[FINSH_HISTORY_LINES - 1], shell->line, shell->line_position))
{
- memcpy(&shell->cmd_history[index][0],
- &shell->cmd_history[index + 1][0], FINSH_CMD_SIZE);
- }
- memset(&shell->cmd_history[index][0], 0, FINSH_CMD_SIZE);
- memcpy(&shell->cmd_history[index][0], shell->line, shell->line_position);
+ /* move history */
+ int index;
+ for (index = 0; index < FINSH_HISTORY_LINES - 1; index ++)
+ {
+ memcpy(&shell->cmd_history[index][0],
+ &shell->cmd_history[index + 1][0], FINSH_CMD_SIZE);
+ }
+ memset(&shell->cmd_history[index][0], 0, FINSH_CMD_SIZE);
+ memcpy(&shell->cmd_history[index][0], shell->line, shell->line_position);
- /* it's the maximum history */
- shell->history_count = FINSH_HISTORY_LINES;
+ /* it's the maximum history */
+ shell->history_count = FINSH_HISTORY_LINES;
+ }
}
else
{
- memset(&shell->cmd_history[shell->history_count][0], 0, FINSH_CMD_SIZE);
- memcpy(&shell->cmd_history[shell->history_count][0], shell->line, shell->line_position);
+ /* if current cmd is same as last cmd, don't push */
+ if (shell->history_count == 0 || memcmp(&shell->cmd_history[shell->history_count - 1], shell->line, shell->line_position))
+ {
+ shell->current_history = shell->history_count;
+ memset(&shell->cmd_history[shell->history_count][0], 0, FINSH_CMD_SIZE);
+ memcpy(&shell->cmd_history[shell->history_count][0], shell->line, shell->line_position);
- /* increase count and set current history position */
- shell->history_count ++;
+ /* increase count and set current history position */
+ shell->history_count ++;
+ }
}
}
shell->current_history = shell->history_count;