Skip to content

Loading…

add REDISCLI_HISTFILE #833

Closed
wants to merge 1 commit into from

3 participants

@charsyam

reading REDISCLI_HISTFILE from shell environment.

and using it.

related issue: #831

@chooper chooper added a commit to chooper/redis that referenced this pull request
@chooper chooper override histfile from env - fixes #831 and copies #833 3ab8321
@mattsta

Tracking in #2133

@mattsta mattsta closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 14, 2012
  1. @openbaas

    add REDISCLI_HISTFILE

    openbaas committed
Showing with 27 additions and 4 deletions.
  1. +27 −4 src/redis-cli.c
View
31 src/redis-cli.c
@@ -753,6 +753,30 @@ static char **convertToSds(int count, char** args) {
return sds;
}
+#define REDISCLI_HISTFILE "REDISCLI_HISTFILE"
+#define DEFAULT_REDISCLI_HISTFILE ".rediscli_history"
+
+static sds getHistoryPath() {
+ char *path = NULL;
+ sds historyPath = NULL;
+
+ path = getenv(REDISCLI_HISTFILE);
+ if (path != NULL && *path != '\0') {
+ if (!strcmp("/dev/null", path)) {
+ return NULL;
+ }
+
+ historyPath = sdscatprintf(sdsempty(), "%s", path);
+ } else {
+ char *home = getenv("HOME");
+ if (home != NULL && *home != '\0') {
+ historyPath = sdscatprintf(sdsempty(), "%s/%s", home, DEFAULT_REDISCLI_HISTFILE);
+ }
+ }
+
+ return historyPath;
+}
+
#define LINE_BUFLEN 4096
static void repl() {
sds historyfile = NULL;
@@ -766,10 +790,9 @@ static void repl() {
/* 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);
}
}
Something went wrong with that request. Please try again.