public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: Marijn Suijten <marijns95@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: luiz.von.dentz@intel.com, Marijn Suijten <marijns95@gmail.com>
Subject: [BlueZ PATCH] shared: shell: Only omit consecutive duplicate history lines.
Date: Sat, 18 Jan 2020 21:44:23 +0100	[thread overview]
Message-ID: <20200118204423.494209-1-marijns95@gmail.com> (raw)

From: Marijn Suijten <marijns95@gmail.com>

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.25.0


             reply	other threads:[~2020-01-18 20:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-18 20:44 Marijn Suijten [this message]
2020-01-20 22:32 ` [BlueZ PATCH] shared: shell: Only omit consecutive duplicate history lines Michał Lowas-Rzechonek
2020-01-22  0:32 ` Luiz Augusto von Dentz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200118204423.494209-1-marijns95@gmail.com \
    --to=marijns95@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=luiz.von.dentz@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox