All of lore.kernel.org
 help / color / mirror / Atom feed
* [BlueZ PATCH] shared: shell: Only omit consecutive duplicate history lines.
@ 2020-01-18 20:44 Marijn Suijten
  2020-01-20 22:32 ` Michał Lowas-Rzechonek
  2020-01-22  0:32 ` Luiz Augusto von Dentz
  0 siblings, 2 replies; 3+ messages in thread
From: Marijn Suijten @ 2020-01-18 20:44 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: luiz.von.dentz, Marijn Suijten

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [BlueZ PATCH] shared: shell: Only omit consecutive duplicate history lines.
  2020-01-18 20:44 [BlueZ PATCH] shared: shell: Only omit consecutive duplicate history lines Marijn Suijten
@ 2020-01-20 22:32 ` Michał Lowas-Rzechonek
  2020-01-22  0:32 ` Luiz Augusto von Dentz
  1 sibling, 0 replies; 3+ messages in thread
From: Michał Lowas-Rzechonek @ 2020-01-20 22:32 UTC (permalink / raw)
  To: Marijn Suijten; +Cc: linux-bluetooth, luiz.von.dentz

On 01/18, Marijn Suijten wrote:
> 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.

Works like a charm, thank you!

I was wondering why btshell utils are so weird and never thought it was
that obvious...

-- 
Michał Lowas-Rzechonek <michal.lowas-rzechonek@silvair.com>
Silvair http://silvair.com
Jasnogórska 44, 31-358 Krakow, POLAND

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [BlueZ PATCH] shared: shell: Only omit consecutive duplicate history lines.
  2020-01-18 20:44 [BlueZ PATCH] shared: shell: Only omit consecutive duplicate history lines Marijn Suijten
  2020-01-20 22:32 ` Michał Lowas-Rzechonek
@ 2020-01-22  0:32 ` Luiz Augusto von Dentz
  1 sibling, 0 replies; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2020-01-22  0:32 UTC (permalink / raw)
  To: Marijn Suijten; +Cc: linux-bluetooth, Luiz Augusto Von Dentz

Hi Marijn,

On Sat, Jan 18, 2020 at 12:46 PM Marijn Suijten <marijns95@gmail.com> wrote:
>
> 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

Applied, thanks.


-- 
Luiz Augusto von Dentz

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-01-22  0:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-18 20:44 [BlueZ PATCH] shared: shell: Only omit consecutive duplicate history lines Marijn Suijten
2020-01-20 22:32 ` Michał Lowas-Rzechonek
2020-01-22  0:32 ` Luiz Augusto von Dentz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.