summaryrefslogtreecommitdiffstats
path: root/tools/lvm.c
diff options
context:
space:
mode:
authorJoe Thornber <thornber@redhat.com>2001-12-17 17:59:58 +0000
committerJoe Thornber <thornber@redhat.com>2001-12-17 17:59:58 +0000
commitaf09a138ce6b52737038114b3d6462492bb36f79 (patch)
tree64205173253c905ca10017086142fa7ebad28e36 /tools/lvm.c
parent1cb025cede99cde85f4d7be6e83fe9008d41c197 (diff)
downloadlvm2-af09a138ce6b52737038114b3d6462492bb36f79.tar.gz
lvm2-af09a138ce6b52737038114b3d6462492bb36f79.tar.xz
lvm2-af09a138ce6b52737038114b3d6462492bb36f79.zip
o history is now saved in ~/.lvm_history
Diffstat (limited to 'tools/lvm.c')
-rw-r--r--tools/lvm.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/tools/lvm.c b/tools/lvm.c
index ba51d36f..413935e2 100644
--- a/tools/lvm.c
+++ b/tools/lvm.c
@@ -1039,6 +1039,43 @@ static char **_completion(const char *text, int start_pos, int end_pos)
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)
{
int argc, ret;
@@ -1047,6 +1084,8 @@ static int shell(void)
rl_readline_name = "lvm";
rl_attempted_completion_function = (CPPFunction *) _completion;
+ _read_history();
+
_interactive = 1;
while (1) {
free(input);
@@ -1080,6 +1119,7 @@ static int shell(void)
continue;
if (!strcmp(argv[0], "quit")) {
+ remove_history(history_length - 1);
log_error("Exiting.");
break;
}
@@ -1090,6 +1130,7 @@ static int shell(void)
argv[0]);
}
+ _write_history();
free(input);
return 0;
}