diff mbox series

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

Message ID 20240326152012.1432957-2-luiz.dentz@gmail.com (mailing list archive)
State Accepted
Commit e6d849f38be30d4a27262c0a8b6c651aac0d79c9
Headers show
Series [BlueZ,v1,1/2] shared/shell: Add script command | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
tedd_an/CheckPatch success CheckPatch PASS
tedd_an/GitLint success Gitlint PASS
tedd_an/IncrementalBuild success Incremental Build PASS

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: