about summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
Diffstat (limited to 'Src')
-rw-r--r--Src/hist.c14
-rw-r--r--Src/lex.c19
2 files changed, 32 insertions, 1 deletions
diff --git a/Src/hist.c b/Src/hist.c
index b7ef52230..70dfac036 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -527,10 +527,20 @@ histsubchar(int c)
     static int marg = -1;
     static zlong mev = -1;
     char *buf, *ptr;
-    char *sline;
+    char *sline, *lexraw_mark;
     Histent ehist;
     size_t buflen;
 
+    /*
+     * If accumulating raw input for use in command substitution,
+     * we don't want the history text, so mark it for later removal.
+     * It would be better to do this at a level above the history
+     * and below the lexer --- but there isn't one.
+     *
+     * Include the character we are attempting to substitute.
+     */
+    lexraw_mark = zshlex_raw_mark(-1); 
+
     /* look, no goto's */
     if (isfirstch && c == hatchar) {
 	int gbal = 0;
@@ -864,6 +874,8 @@ histsubchar(int c)
 	}
     }
 
+    zshlex_raw_back_to_mark(lexraw_mark);
+
     /*
      * Push the expanded value onto the input stack,
      * marking this as a history word for purposes of the alias stack.
diff --git a/Src/lex.c b/Src/lex.c
index 1eb0bc7d7..6b9e94289 100644
--- a/Src/lex.c
+++ b/Src/lex.c
@@ -1871,6 +1871,25 @@ zshlex_raw_back(void)
     lexbuf_raw.len--;
 }
 
+/**/
+char *
+zshlex_raw_mark(int offset)
+{
+    if (!lex_add_raw)
+	return NULL;
+    return lexbuf_raw.ptr + offset;
+}
+
+/**/
+void
+zshlex_raw_back_to_mark(char *mark)
+{
+    if (!lex_add_raw)
+	return;
+    lexbuf_raw.len -= lexbuf_raw.ptr - mark;
+    lexbuf_raw.ptr = mark;
+}
+
 /*
  * Skip (...) for command-style substitutions: $(...), <(...), >(...)
  *