linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH BlueZ] shared/shell: Set rl_readline_name
@ 2018-09-12 11:48 Luiz Augusto von Dentz
  2018-09-17  6:44 ` Luiz Augusto von Dentz
  0 siblings, 1 reply; 2+ messages in thread
From: Luiz Augusto von Dentz @ 2018-09-12 11:48 UTC (permalink / raw)
  To: linux-bluetooth

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

Set rl_readline_name so the binary name can be used in inputrc.
---
 src/shared/shell.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/src/shared/shell.c b/src/shared/shell.c
index 9b0125579..7c3c2daa7 100644
--- a/src/shared/shell.c
+++ b/src/shared/shell.c
@@ -972,6 +972,9 @@ static void rl_init(void)
 	if (data.mode)
 		return;
 
+	/* Allow conditional parsing of the ~/.inputrc file. */
+	rl_readline_name = data.name;
+
 	setlinebuf(stdout);
 	rl_attempted_completion_function = shell_completion;
 
@@ -989,18 +992,11 @@ static const struct option main_options[] = {
 
 static void usage(int argc, char **argv, const struct bt_shell_opt *opt)
 {
-	const char *name;
 	unsigned int i;
 
-	name = strrchr(argv[0], '/');
-	if (!name)
-		name = argv[0];
-	else
-		name++;
-
-	printf("%s ver %s\n", name, VERSION);
+	printf("%s ver %s\n", data.name, VERSION);
 	printf("Usage:\n"
-		"\t%s [--options] [commands]\n", name);
+		"\t%s [--options] [commands]\n", data.name);
 
 	printf("Options:\n");
 
@@ -1030,10 +1026,16 @@ void bt_shell_init(int argc, char **argv, const struct bt_shell_opt *opt)
 	} else
 		snprintf(optstr, sizeof(optstr), "+hvt:");
 
+	data.name = strrchr(argv[0], '/');
+	if (!data.name)
+		data.name = strdup(argv[0]);
+	else
+		data.name = strdup(data.name++);
+
 	while ((c = getopt_long(argc, argv, optstr, options, &index)) != -1) {
 		switch (c) {
 		case 'v':
-			printf("%s: %s\n", argv[0], VERSION);
+			printf("%s: %s\n", data.name, VERSION);
 			exit(EXIT_SUCCESS);
 			return;
 		case 'h':
@@ -1065,7 +1067,6 @@ void bt_shell_init(int argc, char **argv, const struct bt_shell_opt *opt)
 		index = -1;
 	}
 
-	data.name = strdup(argv[0]);
 	bt_shell_set_env("SHELL", data.name);
 
 	data.argc = argc - optind;
-- 
2.17.1

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

* Re: [PATCH BlueZ] shared/shell: Set rl_readline_name
  2018-09-12 11:48 [PATCH BlueZ] shared/shell: Set rl_readline_name Luiz Augusto von Dentz
@ 2018-09-17  6:44 ` Luiz Augusto von Dentz
  0 siblings, 0 replies; 2+ messages in thread
From: Luiz Augusto von Dentz @ 2018-09-17  6:44 UTC (permalink / raw)
  To: linux-bluetooth

Hi,

On Wed, Sep 12, 2018 at 2:48 PM, Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>
> Set rl_readline_name so the binary name can be used in inputrc.
> ---
>  src/shared/shell.c | 23 ++++++++++++-----------
>  1 file changed, 12 insertions(+), 11 deletions(-)
>
> diff --git a/src/shared/shell.c b/src/shared/shell.c
> index 9b0125579..7c3c2daa7 100644
> --- a/src/shared/shell.c
> +++ b/src/shared/shell.c
> @@ -972,6 +972,9 @@ static void rl_init(void)
>         if (data.mode)
>                 return;
>
> +       /* Allow conditional parsing of the ~/.inputrc file. */
> +       rl_readline_name = data.name;
> +
>         setlinebuf(stdout);
>         rl_attempted_completion_function = shell_completion;
>
> @@ -989,18 +992,11 @@ static const struct option main_options[] = {
>
>  static void usage(int argc, char **argv, const struct bt_shell_opt *opt)
>  {
> -       const char *name;
>         unsigned int i;
>
> -       name = strrchr(argv[0], '/');
> -       if (!name)
> -               name = argv[0];
> -       else
> -               name++;
> -
> -       printf("%s ver %s\n", name, VERSION);
> +       printf("%s ver %s\n", data.name, VERSION);
>         printf("Usage:\n"
> -               "\t%s [--options] [commands]\n", name);
> +               "\t%s [--options] [commands]\n", data.name);
>
>         printf("Options:\n");
>
> @@ -1030,10 +1026,16 @@ void bt_shell_init(int argc, char **argv, const struct bt_shell_opt *opt)
>         } else
>                 snprintf(optstr, sizeof(optstr), "+hvt:");
>
> +       data.name = strrchr(argv[0], '/');
> +       if (!data.name)
> +               data.name = strdup(argv[0]);
> +       else
> +               data.name = strdup(data.name++);
> +
>         while ((c = getopt_long(argc, argv, optstr, options, &index)) != -1) {
>                 switch (c) {
>                 case 'v':
> -                       printf("%s: %s\n", argv[0], VERSION);
> +                       printf("%s: %s\n", data.name, VERSION);
>                         exit(EXIT_SUCCESS);
>                         return;
>                 case 'h':
> @@ -1065,7 +1067,6 @@ void bt_shell_init(int argc, char **argv, const struct bt_shell_opt *opt)
>                 index = -1;
>         }
>
> -       data.name = strdup(argv[0]);
>         bt_shell_set_env("SHELL", data.name);
>
>         data.argc = argc - optind;
> --
> 2.17.1

Pushed.



-- 
Luiz Augusto von Dentz

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

end of thread, other threads:[~2018-09-17  6:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-12 11:48 [PATCH BlueZ] shared/shell: Set rl_readline_name Luiz Augusto von Dentz
2018-09-17  6:44 ` 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;
as well as URLs for NNTP newsgroup(s).