Exclude ex cmd from history and register.
authorDaniel Carl <danielcarl@gmx.de>
Fri, 12 Dec 2014 23:12:17 +0000 (00:12 +0100)
committerDaniel Carl <danielcarl@gmx.de>
Fri, 12 Dec 2014 23:12:17 +0000 (00:12 +0100)
If the commands are called with leading ':' or whitespace, the commands are
not written into history or last ex command register ":. This might be useful
if user intend to setup a form filler with over the fifo, to avoid the
credentials to be written unencrypted into vimb's history.

doc/vimb.1
src/ex.c

index 05a49af..730b606 100644 (file)
@@ -379,6 +379,13 @@ Yank the URI or current page into register \fIx\fP and clipboard.
 .BI [ \[char34]x ]Y
 Yank the current selection into register \fIx\fP and clipboard.
 .SH COMMAND MODE
+Commands or ex-commands can be fired from vimb's inputbox, from config file or
+by autocmd. If commands are started from inputbox, they must be prefixed by
+`:'. In case of config file or autocmd the leading colon can be omitted.
+
+Commands that are typed interactive (from inputbox or from fifo) are normally
+recorded into command history and register. To avoid this, the commands can be
+prefixed by one or more additional `:' or whitespace.
 .SS Command Line Editing
 .TP
 .B <Esc>, CTRL\-[, CTRL-C
index b701715..d03a912 100644 (file)
--- a/src/ex.c
+++ b/src/ex.c
@@ -119,7 +119,7 @@ static struct {
 } info = {'\0', PHASE_START};
 
 static void input_activate(void);
-static gboolean parse(const char **input, ExArg *arg);
+static gboolean parse(const char **input, ExArg *arg, gboolean *nohist);
 static gboolean parse_count(const char **input, ExArg *arg);
 static gboolean parse_command_name(const char **input, ExArg *arg);
 static gboolean parse_bang(const char **input, ExArg *arg);
@@ -477,19 +477,22 @@ VbCmdResult ex_run_string(const char *input)
 {
     /* copy to have original command for history */
     const char *in  = input;
+    gboolean nohist = false;
     VbCmdResult res = VB_CMD_ERROR;
     ExArg *arg = g_slice_new0(ExArg);
     arg->lhs   = g_string_new("");
     arg->rhs   = g_string_new("");
 
     while (in && *in) {
-        if (!parse(&in, arg) || !(res = execute(arg))) {
+        if (!parse(&in, arg, &nohist) || !(res = execute(arg))) {
             break;
         }
     }
 
-    history_add(HISTORY_COMMAND, input, NULL);
-    vb_register_add(':', input);
+    if (!nohist) {
+        history_add(HISTORY_COMMAND, input, NULL);
+        vb_register_add(':', input);
+    }
 
     free_cmdarg(arg);
 
@@ -499,7 +502,7 @@ VbCmdResult ex_run_string(const char *input)
 /**
  * Parses given input string into given ExArg pointer.
  */
-static gboolean parse(const char **input, ExArg *arg)
+static gboolean parse(const char **input, ExArg *arg, gboolean *nohist)
 {
     if (!*input || !**input) {
         return false;
@@ -512,6 +515,9 @@ static gboolean parse(const char **input, ExArg *arg)
     /* remove leading whitespace and : */
     while (**input && (**input == ':' || VB_IS_SPACE(**input))) {
         (*input)++;
+        /* Command started with additional ':' or whitespce - don't record it
+         * in history or registry. */
+        *nohist = true;
     }
     parse_count(input, arg);