about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--Doc/Zsh/expn.yo4
-rw-r--r--Src/subst.c27
2 files changed, 31 insertions, 0 deletions
diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo
index 3bc232121..b9af9b83f 100644
--- a/Doc/Zsh/expn.yo
+++ b/Doc/Zsh/expn.yo
@@ -587,6 +587,10 @@ Quote the resulting words with backslashes.
 item(tt(Q))(
 Remove one level of quotes from the resulting words.
 )
+item(tt(%))(
+Expand all tt(%) escapes in the resulting words in the same way as in
+prompts (see noderef(Prompt Expansion)).
+)
 item(tt(X))(
 With this flag parsing errors occuring with the tt(Q) flag or the
 pattern matching forms such as `tt(${)var(name)tt(#)var(pattern)tt(})' 
diff --git a/Src/subst.c b/Src/subst.c
index 1d739c886..7619c94a9 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -730,6 +730,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int ssub)
     int arrasg = 0;
     int eval = 0;
     int aspar = 0;
+    int presc = 0;
     int nojoin = 0;
     char inbrace = 0;		/* != 0 means ${...}, otherwise $... */
     char hkeys = 0;
@@ -934,6 +935,10 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int ssub)
 		    wantt = 1;
 		    break;
 
+		case '%':
+		    presc = 1;
+		    break;
+
 		default:
 		  flagerr:
 		    zerr("error in flags", NULL, 0);
@@ -1569,6 +1574,28 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int ssub)
 		makecapitals(&val);
 	}
     }
+    if (presc) {
+	int len;
+
+	if (isarr) {
+	    char **ap;
+
+	    if (!copied)
+		aval = arrdup(aval), copied = 1;
+	    ap = aval;
+	    for (; *ap; ap++) {
+		unmetafy(*ap, &len);
+		*ap = unmetafy(promptexpand(metafy(*ap, len, META_NOALLOC),
+					    0, NULL, NULL), &len);
+	    }
+	} else {
+	    if (!copied)
+		val = dupstring(val), copied = 1;
+	    unmetafy(val, &len);
+	    val = unmetafy(promptexpand(metafy(val, len, META_NOALLOC),
+					0, NULL, NULL), &len);
+	}
+    }
     if (quotemod) {
 	if (isarr) {
 	    char **ap;