From 4f64816c83e6a6fd44e6dfdfac2fa58d78f7d1ac Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Sat, 18 Jan 2020 21:44:23 +0100 Subject: [PATCH] shared: shell: Only omit consecutive duplicate history lines. Change rl_handler to append duplicate history, as long as it isn't identical to the last line. It prevents consecutive duplicates while still having an accurate overview of the most recent commands used, mimicking most modern shells. This addresses my only major gripe with bluetoothctl: pressing UP does not retrieve the last typed command when it is a duplicate of something else written (much) earlier in the history. It is especially noticeable when needing the same command repeatedly. --- src/shared/shell.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/shared/shell.c b/src/shared/shell.c index cfdcc76c4..2e094b8f1 100644 --- a/src/shared/shell.c +++ b/src/shared/shell.c @@ -681,6 +681,7 @@ int bt_shell_release_prompt(const char *input) static void rl_handler(char *input) { wordexp_t w; + HIST_ENTRY *last; if (!input) { rl_insert_text("quit"); @@ -696,7 +697,9 @@ static void rl_handler(char *input) if (!bt_shell_release_prompt(input)) goto done; - if (history_search(input, -1)) + last = history_get(history_length + history_base - 1); + /* append only if input is different from previous command */ + if (!last || strcmp(input, last->line)) add_history(input); if (data.monitor) -- 2.47.3