From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ 2/2] shared/shell: Add history support
Date: Wed, 13 Jun 2018 17:39:41 +0300 [thread overview]
Message-ID: <20180613143941.11139-2-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20180613143941.11139-1-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This uses read_history/write_history to load and save input history.
---
src/shared/shell.c | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/src/shared/shell.c b/src/shared/shell.c
index 2353a5e22..1efe2f99c 100644
--- a/src/shared/shell.c
+++ b/src/shared/shell.c
@@ -64,6 +64,7 @@ struct bt_shell_env {
static struct {
bool init;
char *name;
+ char history[256];
int argc;
char **argv;
bool mode;
@@ -892,6 +893,41 @@ static struct io *setup_signalfd(void)
return io;
}
+static void rl_init_history(void)
+{
+ char *dir;
+
+ memset(data.history, 0, sizeof(data.history));
+
+ dir = getenv("XDG_CACHE_HOME");
+ if (dir) {
+ snprintf(data.history, sizeof(data.history), "%s/.%s_history",
+ dir, data.name);
+ goto done;
+ }
+
+ dir = getenv("HOME");
+ if (dir) {
+ snprintf(data.history, sizeof(data.history),
+ "%s/.cache/.%s_history", dir, data.name);
+ goto done;
+ }
+
+ dir = getenv("PWD");
+ if (dir) {
+ snprintf(data.history, sizeof(data.history), "%s/.%s_history",
+ dir, data.name);
+ goto done;
+ }
+
+ return;
+
+done:
+ printf("HISTORY=%s\n", data.history);
+ read_history(data.history);
+ bt_shell_set_env("HISTORY", data.history);
+}
+
static void rl_init(void)
{
if (data.mode)
@@ -902,6 +938,8 @@ static void rl_init(void)
rl_erase_empty_line = 1;
rl_callback_handler_install(NULL, rl_handler);
+
+ rl_init_history();
}
static const struct option main_options[] = {
@@ -1007,6 +1045,9 @@ static void rl_cleanup(void)
if (data.mode)
return;
+ if (data.history[0] != '\0')
+ write_history(data.history);
+
rl_message("");
rl_callback_handler_remove();
}
--
2.17.1
prev parent reply other threads:[~2018-06-13 14:39 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-13 14:39 [PATCH BlueZ 1/2] shared/shell: Set shell name on SHELL env Luiz Augusto von Dentz
2018-06-13 14:39 ` Luiz Augusto von Dentz [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180613143941.11139-2-luiz.dentz@gmail.com \
--to=luiz.dentz@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).