1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-03 05:18:29 +03:00

o history is now saved in ~/.lvm_history

This commit is contained in:
Joe Thornber 2001-12-17 17:59:58 +00:00
parent 1cb025cede
commit af09a138ce

View File

@ -1039,6 +1039,43 @@ static char **_completion(const char *text, int start_pos, int end_pos)
return match_list; return match_list;
} }
static int _hist_file(char *buffer, size_t size)
{
char *e = getenv("HOME");
if (lvm_snprintf(buffer, size, "%s/.lvm_history", e) < 0) {
log_err("History file path too long (%s/.lvm_history).", e);
return 0;
}
return 1;
}
#define MAX_HISTORY 100
static void _read_history(void)
{
char hist_file[PATH_MAX];
if (!_hist_file(hist_file, sizeof(hist_file)))
return;
if (read_history(hist_file))
log_very_verbose("Couldn't read history from %s.", hist_file);
stifle_history(MAX_HISTORY);
}
static void _write_history(void)
{
char hist_file[PATH_MAX];
if (!_hist_file(hist_file, sizeof(hist_file)))
return;
if (write_history(hist_file))
log_very_verbose("Couldn't write history to %s.", hist_file);
}
static int shell(void) static int shell(void)
{ {
int argc, ret; int argc, ret;
@ -1047,6 +1084,8 @@ static int shell(void)
rl_readline_name = "lvm"; rl_readline_name = "lvm";
rl_attempted_completion_function = (CPPFunction *) _completion; rl_attempted_completion_function = (CPPFunction *) _completion;
_read_history();
_interactive = 1; _interactive = 1;
while (1) { while (1) {
free(input); free(input);
@ -1080,6 +1119,7 @@ static int shell(void)
continue; continue;
if (!strcmp(argv[0], "quit")) { if (!strcmp(argv[0], "quit")) {
remove_history(history_length - 1);
log_error("Exiting."); log_error("Exiting.");
break; break;
} }
@ -1090,6 +1130,7 @@ static int shell(void)
argv[0]); argv[0]);
} }
_write_history();
free(input); free(input);
return 0; return 0;
} }