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

Re: promptsubst and empty variables



On Sun, 14 Sep 2008 09:43:22 -0700
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Sep 14, 11:24am, Frank Terbeck wrote:
> }
> } I am seeing some weirdness using prompt_subst and empty variables in
> } RPS1 (from zsh -f):
> } 
> } [snip]
> } setopt promptsubst
> } RPROMPT='${foo}'
> 
> I get the misplaced cursor right here; there doesn't need to be a value
> assigned to PROMPT with or without a substitution in it.
> 
> The problem is that singsub() called from promptexpand() is returning
> nulstring, which is the Nularg token followed by a NUL byte.

I hope, actually, it's dupstring(nulstring), or substitution is a bit
broken.

I don't think we need the Nularg in this case since although the string is
metafied we're not doing anything special with tokens.  However, I've never
understood what this was for in the first place, so I may have missed
something.  If I have, however, we're not going to find out without trying
it.

Index: Src/prompt.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/prompt.c,v
retrieving revision 1.52
diff -u -r1.52 prompt.c
--- Src/prompt.c	24 Jun 2008 08:44:16 -0000	1.52
+++ Src/prompt.c	15 Sep 2008 14:27:44 -0000
@@ -169,6 +169,12 @@
 	s = dupstring(s);
 	if (!parsestr(s))
 	    singsub(&s);
+	/*
+	 * We don't need the special Nularg hack here and we're
+	 * going to be using Nularg for other things.
+	 */
+	if (*s == Nularg && s[1] == '\0')
+	    *s = '\0';
 
 	/* Ignore errors and status change in prompt substitution */
 	errflag = olderr;


-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070



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