public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ] tools: Only add unique entries to readline history
@ 2017-09-18  9:23 Luiz Augusto von Dentz
  2017-09-19  2:14 ` ERAMOTO Masaya
  0 siblings, 1 reply; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2017-09-18  9:23 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Don't add duplicate commands to historym this is similar to what
HISTCONTROL=ignoredups does.
---
 client/main.c            | 3 ++-
 tools/bluetooth-player.c | 4 +++-
 tools/btmgmt.c           | 3 ++-
 tools/obex-client-tool.c | 3 ++-
 tools/obexctl.c          | 3 ++-
 5 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/client/main.c b/client/main.c
index 2cb449fd5..282e84003 100644
--- a/client/main.c
+++ b/client/main.c
@@ -2644,7 +2644,8 @@ static void rl_handler(char *input)
 	if (!rl_release_prompt(input))
 		goto done;
 
-	add_history(input);
+	if (history_search(input, -1))
+		add_history(input);
 
 	cmd = strtok_r(input, " ", &arg);
 	if (!cmd)
diff --git a/tools/bluetooth-player.c b/tools/bluetooth-player.c
index 9e199970d..c95b7497f 100644
--- a/tools/bluetooth-player.c
+++ b/tools/bluetooth-player.c
@@ -1086,7 +1086,9 @@ static void rl_handler(char *input)
 		goto done;
 
 	g_strstrip(input);
-	add_history(input);
+
+	if (history_search(input, -1))
+		add_history(input);
 
 	argv = g_strsplit(input, " ", -1);
 	if (argv == NULL)
diff --git a/tools/btmgmt.c b/tools/btmgmt.c
index e7ea69937..e454d864d 100644
--- a/tools/btmgmt.c
+++ b/tools/btmgmt.c
@@ -4664,7 +4664,8 @@ static void rl_handler(char *input)
 	if (prompt_input(input))
 		goto done;
 
-	add_history(input);
+	if (history_search(input, -1))
+		add_history(input);
 
 	if (wordexp(input, &w, WRDE_NOCMD))
 		goto done;
diff --git a/tools/obex-client-tool.c b/tools/obex-client-tool.c
index d0ba8a651..d74ac77a1 100644
--- a/tools/obex-client-tool.c
+++ b/tools/obex-client-tool.c
@@ -242,7 +242,8 @@ static void parse_line(char *line_read)
 		return;
 	}
 
-	add_history(line_read);
+	if (history_search(input, -1))
+		add_history(input);
 
 	g_shell_parse_argv(line_read, &argcp, &argvp, NULL);
 
diff --git a/tools/obexctl.c b/tools/obexctl.c
index 46943d682..ece50f682 100644
--- a/tools/obexctl.c
+++ b/tools/obexctl.c
@@ -2081,7 +2081,8 @@ static void rl_handler(char *input)
 	if (!strlen(input))
 		goto done;
 
-	add_history(input);
+	if (history_search(input, -1))
+		add_history(input);
 
 	if (wordexp(input, &w, WRDE_NOCMD))
 		goto done;
-- 
2.13.5


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

* Re: [PATCH BlueZ] tools: Only add unique entries to readline history
  2017-09-18  9:23 [PATCH BlueZ] tools: Only add unique entries to readline history Luiz Augusto von Dentz
@ 2017-09-19  2:14 ` ERAMOTO Masaya
  2017-09-19  7:08   ` Luiz Augusto von Dentz
  0 siblings, 1 reply; 4+ messages in thread
From: ERAMOTO Masaya @ 2017-09-19  2:14 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: linux-bluetooth

Hi Luiz,

On 09/18/2017 06:23 PM, Luiz Augusto von Dentz wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
> 
> Don't add duplicate commands to historym this is similar to what
> HISTCONTROL=ignoredups does.
> ---
>  client/main.c            | 3 ++-
>  tools/bluetooth-player.c | 4 +++-
>  tools/btmgmt.c           | 3 ++-
>  tools/obex-client-tool.c | 3 ++-
>  tools/obexctl.c          | 3 ++-
>  5 files changed, 11 insertions(+), 5 deletions(-)
> 
> diff --git a/client/main.c b/client/main.c
> index 2cb449fd5..282e84003 100644
> --- a/client/main.c
> +++ b/client/main.c
> @@ -2644,7 +2644,8 @@ static void rl_handler(char *input)
>  	if (!rl_release_prompt(input))
>  		goto done;
>  
> -	add_history(input);
> +	if (history_search(input, -1))
> +		add_history(input);
>  

I think it is better to add g_strstrip(), since this patch adds a
command typed all characters to history and then adds the complemented
command to history when it have white-space.

>  	cmd = strtok_r(input, " ", &arg);
>  	if (!cmd)
> diff --git a/tools/bluetooth-player.c b/tools/bluetooth-player.c
> index 9e199970d..c95b7497f 100644
> --- a/tools/bluetooth-player.c
> +++ b/tools/bluetooth-player.c
> @@ -1086,7 +1086,9 @@ static void rl_handler(char *input)
>  		goto done;
>  
>  	g_strstrip(input);
> -	add_history(input);
> +
> +	if (history_search(input, -1))
> +		add_history(input);
>  
>  	argv = g_strsplit(input, " ", -1);
>  	if (argv == NULL)
> diff --git a/tools/btmgmt.c b/tools/btmgmt.c
> index e7ea69937..e454d864d 100644
> --- a/tools/btmgmt.c
> +++ b/tools/btmgmt.c
> @@ -4664,7 +4664,8 @@ static void rl_handler(char *input)
>  	if (prompt_input(input))
>  		goto done;
>  
> -	add_history(input);
> +	if (history_search(input, -1))
> +		add_history(input);
>  
>  	if (wordexp(input, &w, WRDE_NOCMD))
>  		goto done;
> diff --git a/tools/obex-client-tool.c b/tools/obex-client-tool.c
> index d0ba8a651..d74ac77a1 100644
> --- a/tools/obex-client-tool.c
> +++ b/tools/obex-client-tool.c
> @@ -242,7 +242,8 @@ static void parse_line(char *line_read)
>  		return;
>  	}
>  
> -	add_history(line_read);
> +	if (history_search(input, -1))
> +		add_history(input);

line_read is correct.

>  
>  	g_shell_parse_argv(line_read, &argcp, &argvp, NULL);
>  
> diff --git a/tools/obexctl.c b/tools/obexctl.c
> index 46943d682..ece50f682 100644
> --- a/tools/obexctl.c
> +++ b/tools/obexctl.c
> @@ -2081,7 +2081,8 @@ static void rl_handler(char *input)
>  	if (!strlen(input))
>  		goto done;
>  
> -	add_history(input);
> +	if (history_search(input, -1))
> +		add_history(input);
>  
>  	if (wordexp(input, &w, WRDE_NOCMD))
>  		goto done;
> 


Regards,
Eramoto


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

* Re: [PATCH BlueZ] tools: Only add unique entries to readline history
  2017-09-19  2:14 ` ERAMOTO Masaya
@ 2017-09-19  7:08   ` Luiz Augusto von Dentz
  2017-09-20 12:49     ` Luiz Augusto von Dentz
  0 siblings, 1 reply; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2017-09-19  7:08 UTC (permalink / raw)
  To: ERAMOTO Masaya; +Cc: linux-bluetooth@vger.kernel.org

Hi Eramoto,

On Tue, Sep 19, 2017 at 5:14 AM, ERAMOTO Masaya
<eramoto.masaya@jp.fujitsu.com> wrote:
> Hi Luiz,
>
> On 09/18/2017 06:23 PM, Luiz Augusto von Dentz wrote:
>> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>>
>> Don't add duplicate commands to historym this is similar to what
>> HISTCONTROL=ignoredups does.
>> ---
>>  client/main.c            | 3 ++-
>>  tools/bluetooth-player.c | 4 +++-
>>  tools/btmgmt.c           | 3 ++-
>>  tools/obex-client-tool.c | 3 ++-
>>  tools/obexctl.c          | 3 ++-
>>  5 files changed, 11 insertions(+), 5 deletions(-)
>>
>> diff --git a/client/main.c b/client/main.c
>> index 2cb449fd5..282e84003 100644
>> --- a/client/main.c
>> +++ b/client/main.c
>> @@ -2644,7 +2644,8 @@ static void rl_handler(char *input)
>>       if (!rl_release_prompt(input))
>>               goto done;
>>
>> -     add_history(input);
>> +     if (history_search(input, -1))
>> +             add_history(input);
>>
>
> I think it is better to add g_strstrip(), since this patch adds a
> command typed all characters to history and then adds the complemented
> command to history when it have white-space.

Yep, but as a separate change, this part of handling should really go
into a common code so we don't have to keep duplicating this on every
tool.

>>       cmd = strtok_r(input, " ", &arg);
>>       if (!cmd)
>> diff --git a/tools/bluetooth-player.c b/tools/bluetooth-player.c
>> index 9e199970d..c95b7497f 100644
>> --- a/tools/bluetooth-player.c
>> +++ b/tools/bluetooth-player.c
>> @@ -1086,7 +1086,9 @@ static void rl_handler(char *input)
>>               goto done;
>>
>>       g_strstrip(input);
>> -     add_history(input);
>> +
>> +     if (history_search(input, -1))
>> +             add_history(input);
>>
>>       argv = g_strsplit(input, " ", -1);
>>       if (argv == NULL)
>> diff --git a/tools/btmgmt.c b/tools/btmgmt.c
>> index e7ea69937..e454d864d 100644
>> --- a/tools/btmgmt.c
>> +++ b/tools/btmgmt.c
>> @@ -4664,7 +4664,8 @@ static void rl_handler(char *input)
>>       if (prompt_input(input))
>>               goto done;
>>
>> -     add_history(input);
>> +     if (history_search(input, -1))
>> +             add_history(input);
>>
>>       if (wordexp(input, &w, WRDE_NOCMD))
>>               goto done;
>> diff --git a/tools/obex-client-tool.c b/tools/obex-client-tool.c
>> index d0ba8a651..d74ac77a1 100644
>> --- a/tools/obex-client-tool.c
>> +++ b/tools/obex-client-tool.c
>> @@ -242,7 +242,8 @@ static void parse_line(char *line_read)
>>               return;
>>       }
>>
>> -     add_history(line_read);
>> +     if (history_search(input, -1))
>> +             add_history(input);
>
> line_read is correct.

Good catch, will fix it.

>>
>>       g_shell_parse_argv(line_read, &argcp, &argvp, NULL);
>>
>> diff --git a/tools/obexctl.c b/tools/obexctl.c
>> index 46943d682..ece50f682 100644
>> --- a/tools/obexctl.c
>> +++ b/tools/obexctl.c
>> @@ -2081,7 +2081,8 @@ static void rl_handler(char *input)
>>       if (!strlen(input))
>>               goto done;
>>
>> -     add_history(input);
>> +     if (history_search(input, -1))
>> +             add_history(input);
>>
>>       if (wordexp(input, &w, WRDE_NOCMD))
>>               goto done;
>>
>
>
> Regards,
> Eramoto
>



-- 
Luiz Augusto von Dentz

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

* Re: [PATCH BlueZ] tools: Only add unique entries to readline history
  2017-09-19  7:08   ` Luiz Augusto von Dentz
@ 2017-09-20 12:49     ` Luiz Augusto von Dentz
  0 siblings, 0 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2017-09-20 12:49 UTC (permalink / raw)
  To: ERAMOTO Masaya; +Cc: linux-bluetooth@vger.kernel.org

Hi,

On Tue, Sep 19, 2017 at 10:08 AM, Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
> Hi Eramoto,
>
> On Tue, Sep 19, 2017 at 5:14 AM, ERAMOTO Masaya
> <eramoto.masaya@jp.fujitsu.com> wrote:
>> Hi Luiz,
>>
>> On 09/18/2017 06:23 PM, Luiz Augusto von Dentz wrote:
>>> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>>>
>>> Don't add duplicate commands to historym this is similar to what
>>> HISTCONTROL=ignoredups does.
>>> ---
>>>  client/main.c            | 3 ++-
>>>  tools/bluetooth-player.c | 4 +++-
>>>  tools/btmgmt.c           | 3 ++-
>>>  tools/obex-client-tool.c | 3 ++-
>>>  tools/obexctl.c          | 3 ++-
>>>  5 files changed, 11 insertions(+), 5 deletions(-)
>>>
>>> diff --git a/client/main.c b/client/main.c
>>> index 2cb449fd5..282e84003 100644
>>> --- a/client/main.c
>>> +++ b/client/main.c
>>> @@ -2644,7 +2644,8 @@ static void rl_handler(char *input)
>>>       if (!rl_release_prompt(input))
>>>               goto done;
>>>
>>> -     add_history(input);
>>> +     if (history_search(input, -1))
>>> +             add_history(input);
>>>
>>
>> I think it is better to add g_strstrip(), since this patch adds a
>> command typed all characters to history and then adds the complemented
>> command to history when it have white-space.
>
> Yep, but as a separate change, this part of handling should really go
> into a common code so we don't have to keep duplicating this on every
> tool.
>
>>>       cmd = strtok_r(input, " ", &arg);
>>>       if (!cmd)
>>> diff --git a/tools/bluetooth-player.c b/tools/bluetooth-player.c
>>> index 9e199970d..c95b7497f 100644
>>> --- a/tools/bluetooth-player.c
>>> +++ b/tools/bluetooth-player.c
>>> @@ -1086,7 +1086,9 @@ static void rl_handler(char *input)
>>>               goto done;
>>>
>>>       g_strstrip(input);
>>> -     add_history(input);
>>> +
>>> +     if (history_search(input, -1))
>>> +             add_history(input);
>>>
>>>       argv = g_strsplit(input, " ", -1);
>>>       if (argv == NULL)
>>> diff --git a/tools/btmgmt.c b/tools/btmgmt.c
>>> index e7ea69937..e454d864d 100644
>>> --- a/tools/btmgmt.c
>>> +++ b/tools/btmgmt.c
>>> @@ -4664,7 +4664,8 @@ static void rl_handler(char *input)
>>>       if (prompt_input(input))
>>>               goto done;
>>>
>>> -     add_history(input);
>>> +     if (history_search(input, -1))
>>> +             add_history(input);
>>>
>>>       if (wordexp(input, &w, WRDE_NOCMD))
>>>               goto done;
>>> diff --git a/tools/obex-client-tool.c b/tools/obex-client-tool.c
>>> index d0ba8a651..d74ac77a1 100644
>>> --- a/tools/obex-client-tool.c
>>> +++ b/tools/obex-client-tool.c
>>> @@ -242,7 +242,8 @@ static void parse_line(char *line_read)
>>>               return;
>>>       }
>>>
>>> -     add_history(line_read);
>>> +     if (history_search(input, -1))
>>> +             add_history(input);
>>
>> line_read is correct.
>
> Good catch, will fix it.
>
>>>
>>>       g_shell_parse_argv(line_read, &argcp, &argvp, NULL);
>>>
>>> diff --git a/tools/obexctl.c b/tools/obexctl.c
>>> index 46943d682..ece50f682 100644
>>> --- a/tools/obexctl.c
>>> +++ b/tools/obexctl.c
>>> @@ -2081,7 +2081,8 @@ static void rl_handler(char *input)
>>>       if (!strlen(input))
>>>               goto done;
>>>
>>> -     add_history(input);
>>> +     if (history_search(input, -1))
>>> +             add_history(input);
>>>
>>>       if (wordexp(input, &w, WRDE_NOCMD))
>>>               goto done;
>>>
>>
>>
>> Regards,
>> Eramoto
>>

Applied.

-- 
Luiz Augusto von Dentz

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

end of thread, other threads:[~2017-09-20 12:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-18  9:23 [PATCH BlueZ] tools: Only add unique entries to readline history Luiz Augusto von Dentz
2017-09-19  2:14 ` ERAMOTO Masaya
2017-09-19  7:08   ` Luiz Augusto von Dentz
2017-09-20 12:49     ` Luiz Augusto von Dentz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox