Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: new parameter flag?



Dunno if you like this...

This adds the `%' flag to parameter expansion. It makes the result of
the expansion undergo prompt expansion. For things like

  POSTEDIT="${(%):-%b}"
  day="${${(%):-%W}[1,2]}"

Maybe we should finally implement the non-forking form of `$(...)'
instead...

Bye
 Sven

--- os/subst.c	Sun Aug 29 20:00:19 1999
+++ Src/subst.c	Sun Aug 29 19:51:01 1999
@@ -730,6 +730,7 @@
     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 @@
 		    wantt = 1;
 		    break;
 
+		case '%':
+		    presc = 1;
+		    break;
+
 		default:
 		  flagerr:
 		    zerr("error in flags", NULL, 0);
@@ -1567,6 +1572,28 @@
 		makelowercase(&val);
 	    else
 		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) {
diff -u od/Zsh/expn.yo Doc/Zsh/expn.yo
--- od/Zsh/expn.yo	Sun Aug 29 20:00:46 1999
+++ Doc/Zsh/expn.yo	Sun Aug 29 19:58:10 1999
@@ -587,6 +587,10 @@
 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(})' 

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



Messages sorted by: Reverse Date, Date, Thread, Author