summaryrefslogtreecommitdiff
path: root/src/redis-cli.c
diff options
context:
space:
mode:
authorSalvatore Sanfilippo <antirez@gmail.com>2014-12-10 15:28:41 +0100
committerSalvatore Sanfilippo <antirez@gmail.com>2014-12-10 15:28:41 +0100
commit3da87b70ddb8c4ff49b3a32424baf24f0a88c2fa (patch)
treeb76513783cb2f24aca692372f671eb7ed697060e /src/redis-cli.c
parentd8158771b552d0ef7f42befd894478f5fa00b894 (diff)
parent3ab832193cb58a876eba9c62df3fc0ea3814453a (diff)
downloadredis-3da87b70ddb8c4ff49b3a32424baf24f0a88c2fa.tar.gz
Merge pull request #2133 from chooper/histfile-override
override histfile from env - fixes #831 and copies #833
Diffstat (limited to 'src/redis-cli.c')
-rw-r--r--src/redis-cli.c33
1 files changed, 29 insertions, 4 deletions
diff --git a/src/redis-cli.c b/src/redis-cli.c
index d73d37390..67730bb3e 100644
--- a/src/redis-cli.c
+++ b/src/redis-cli.c
@@ -60,6 +60,8 @@
#define OUTPUT_CSV 2
#define REDIS_CLI_KEEPALIVE_INTERVAL 15 /* seconds */
#define REDIS_CLI_DEFAULT_PIPE_TIMEOUT 30 /* seconds */
+#define REDIS_CLI_HISTFILE_ENV "REDISCLI_HISTFILE"
+#define REDIS_CLI_HISTFILE_DEFAULT ".rediscli_history"
static redisContext *context;
static struct config {
@@ -138,6 +140,30 @@ static void cliRefreshPrompt(void) {
snprintf(config.prompt+len,sizeof(config.prompt)-len,"> ");
}
+static sds getHistoryPath() {
+ char *path = NULL;
+ sds historyPath = NULL;
+
+ /* check the env for a histfile override */
+ path = getenv(REDIS_CLI_HISTFILE_ENV);
+ if (path != NULL && *path != '\0') {
+ if (!strcmp("/dev/null", path)) {
+ return NULL;
+ }
+
+ /* if the env is set, return it */
+ historyPath = sdscatprintf(sdsempty(), "%s", path);
+ } else {
+ char *home = getenv("HOME");
+ if (home != NULL && *home != '\0') {
+ /* otherwise, return the default */
+ historyPath = sdscatprintf(sdsempty(), "%s/%s", home, REDIS_CLI_HISTFILE_DEFAULT);
+ }
+ }
+
+ return historyPath;
+}
+
/*------------------------------------------------------------------------------
* Help functions
*--------------------------------------------------------------------------- */
@@ -891,10 +917,9 @@ static void repl(void) {
/* Only use history when stdin is a tty. */
if (isatty(fileno(stdin))) {
- history = 1;
-
- if (getenv("HOME") != NULL) {
- historyfile = sdscatprintf(sdsempty(),"%s/.rediscli_history",getenv("HOME"));
+ historyfile = getHistoryPath();
+ if (historyfile != NULL) {
+ history = 1;
linenoiseHistoryLoad(historyfile);
}
}