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

Re: Bug#201685: zsh: bug in prompt expansion



Clint Adams wrote:
> I don't remember if this was discussed before.
> 
> On Thu, Jul 17, 2003 at 11:33:11AM +0200, Martin Godisch wrote:
> > 
> > After PROMPT='%~%1(C./.) ' the full prompt should be `/ ' in the root
> > directory, because the absolute path `/' does not have at least one element
> .

This would fix this.

Index: Doc/Zsh/prompt.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/prompt.yo,v
retrieving revision 1.6
diff -u -r1.6 prompt.yo
--- Doc/Zsh/prompt.yo	2 Nov 2001 12:35:32 -0000	1.6
+++ Doc/Zsh/prompt.yo	26 Jul 2004 17:12:13 -0000
@@ -217,11 +217,13 @@
 sitem(tt(?))(True if the exit status of the last command was var(n).)
 sitem(tt(_))(True if at least var(n) shell constructs were started.)
 sxitem(tt(C))
-sitem(tt(/))(True if the current absolute path has at least var(n) elements.)
+sitem(tt(/))(True if the current absolute path has at least var(n) elements
+relative to the root directory, hence tt(/) is counted as 0 elements.)
 sxitem(tt(c))
 sxitem(tt(.))
 sitem(tt(~))(True if the current path, with prefix replacement, has at
-least var(n) elements.)
+least var(n) elements relative to the root directory, hence tt(/) is
+counted as 0 elements.)
 sitem(tt(D))(True if the month is equal to var(n) (January = 0).)
 sitem(tt(d))(True if the day of the month is equal to var(n).)
 sitem(tt(g))(True if the effective gid of the current process is var(n).)
Index: Src/prompt.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/prompt.c,v
retrieving revision 1.19
diff -u -r1.19 prompt.c
--- Src/prompt.c	22 Jun 2004 13:10:02 -0000	1.19
+++ Src/prompt.c	26 Jul 2004 17:12:14 -0000
@@ -244,9 +244,12 @@
 		    if ((nd = finddir(ss))) {
 			arg--;
 			ss += strlen(nd->dir);
-		    }
+		    } /*FALLTHROUGH*/
 		case '/':
 		case 'C':
+		    /* `/' gives 0, `/any' gives 1, etc. */
+		    if (*ss++ == '/' && *ss)
+			arg--;
 		    for (; *ss; ss++)
 			if (*ss == '/')
 			    arg--;

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited. 
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************



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