Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
1f4074e9
Commit
1f4074e9
authored
Nov 10, 2014
by
Charles Hooper
Committed by
antirez
Feb 10, 2015
Browse files
override histfile from env - fixes #831 and copies #833
parent
9e83d2d2
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/redis-cli.c
View file @
1f4074e9
...
...
@@ -61,6 +61,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
{
...
...
@@ -142,6 +144,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
*--------------------------------------------------------------------------- */
...
...
@@ -906,10 +932,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
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment