diff mbox series

[BlueZ,v1,2/2] shared/shell: Add commands from scripts to history

Message ID 20240326152012.1432957-2-luiz.dentz@gmail.com
State New
Headers show
Series [BlueZ,v1,1/2] shared/shell: Add script command | expand

Commit Message

Luiz Augusto von Dentz March 26, 2024, 3:20 p.m. UTC
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This enables saving the commands run from a script to also be visible in
the history.
---
 src/shared/shell.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/src/shared/shell.c b/src/shared/shell.c
index d68d6798f117..f3f7bab9a616 100644
--- a/src/shared/shell.c
+++ b/src/shared/shell.c
@@ -863,8 +863,6 @@  int bt_shell_release_prompt(const char *input)
 
 static void rl_handler(char *input)
 {
-	HIST_ENTRY *last;
-
 	if (!input) {
 		rl_insert_text("quit");
 		rl_redisplay();
@@ -879,14 +877,6 @@  static void rl_handler(char *input)
 	if (!bt_shell_release_prompt(input))
 		goto done;
 
-	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)
-		bt_log_printf(0xffff, data.name, LOG_INFO, "%s", input);
-
 	bt_shell_exec(input);
 
 done:
@@ -1404,12 +1394,21 @@  int bt_shell_run(void)
 
 int bt_shell_exec(const char *input)
 {
+	HIST_ENTRY *last;
 	wordexp_t w;
 	int err;
 
 	if (!input)
 		return 0;
 
+	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)
+		bt_log_printf(0xffff, data.name, LOG_INFO, "%s", input);
+
 	err = wordexp(input, &w, WRDE_NOCMD);
 	switch (err) {
 	case WRDE_BADCHAR: