[libvirt] [PATCH] virsh: new environment variable VIRSH_HISTSIZE

Pavel Raiskup praiskup at redhat.com
Sun Oct 27 09:17:29 UTC 2013


Allow adjust the number of commands to remember in the command
history.

* tools/virsh.c (vshReadlineInit): Read and sanity the
VIRSH_HISTSIZE variable.
(VIRSH_HISTSIZE_MAX): New constant.
* tools/virsh.pod: Document VIRSH_HISTSIZE variable.
---
 tools/virsh.c   | 17 ++++++++++++++++-
 tools/virsh.pod |  5 +++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index bad78c9..58bc841 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -2748,11 +2748,14 @@ vshReadlineCompletion(const char *text, int start,
     return matches;
 }
 
+#define VIRSH_HISTSIZE_MAX 500000
 
 static int
 vshReadlineInit(vshControl *ctl)
 {
     char *userdir = NULL;
+    int max_history = 500;
+    char *histsize_str;
 
     /* Allow conditional parsing of the ~/.inputrc file. */
     rl_readline_name = "virsh";
@@ -2761,7 +2764,19 @@ vshReadlineInit(vshControl *ctl)
     rl_attempted_completion_function = vshReadlineCompletion;
 
     /* Limit the total size of the history buffer */
-    stifle_history(500);
+    if ((histsize_str = getenv("VIRSH_HISTSIZE"))) {
+        if (virStrToLong_i(histsize_str, NULL, 10, &max_history) < 0) {
+            vshError(ctl, "%s", _("Bad $VIRSH_HISTSIZE value."));
+            VIR_FREE(userdir);
+            return -1;
+        } else if (max_history > VIRSH_HISTSIZE_MAX || max_history < 0) {
+            vshError(ctl, _("$VIRSH_HISTSIZE value should be between 0 and %d"),
+                     VIRSH_HISTSIZE_MAX);
+            VIR_FREE(userdir);
+            return -1;
+        }
+    }
+    stifle_history(max_history);
 
     /* Prepare to read/write history from/to the $XDG_CACHE_HOME/virsh/history file */
     userdir = virGetUserCacheDirectory();
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 23d17c4..dac9a08 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -3349,6 +3349,11 @@ The editor to use by the B<edit> and related options.
 The editor to use by the B<edit> and related options, if C<VISUAL>
 is not set.
 
+=item VIRSH_HISTSIZE
+
+The number of commands to remember in the command  history.  The
+default value is 500.
+
 =item LIBVIRT_DEBUG=LEVEL
 
 Turn on verbose debugging of all libvirt API calls. Valid levels are
-- 
1.8.3.1




More information about the libvir-list mailing list