From 2992a5502706f44b840dd8ef886647dd2f06efe4 Mon Sep 17 00:00:00 2001 From: Steve Bennett Date: Wed, 13 Jul 2011 16:44:29 +1000 Subject: Don't load and save history if not on a tty If jimsh is run in interactive mode but without a tty, don't bother to load and save line editing history. Signed-off-by: Steve Bennett --- jim-interactive.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'jim-interactive.c') diff --git a/jim-interactive.c b/jim-interactive.c index 90976ce..658e8d8 100644 --- a/jim-interactive.c +++ b/jim-interactive.c @@ -4,6 +4,7 @@ #include "jimautoconf.h" #ifdef USE_LINENOISE +#include #include "linenoise.h" #else @@ -32,7 +33,7 @@ int Jim_InteractivePrompt(Jim_Interp *interp) const char *home; home = getenv("HOME"); - if (home) { + if (home && isatty(STDIN_FILENO)) { int history_len = strlen(home) + sizeof("/.jim_history"); history_file = Jim_Alloc(history_len); snprintf(history_file, history_len, "%s/.jim_history", home); @@ -109,7 +110,9 @@ int Jim_InteractivePrompt(Jim_Interp *interp) } linenoiseHistoryAdd(Jim_String(scriptObjPtr)); - linenoiseHistorySave(history_file); + if (history_file) { + linenoiseHistorySave(history_file); + } #endif retcode = Jim_EvalObj(interp, scriptObjPtr); Jim_DecrRefCount(interp, scriptObjPtr); -- cgit v1.1