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

I sent a patch for this but can't see any sign of it having got
anywhere.

This should do what was asked for.  It's more logical but I don't know
if anyone out there is expecting the code simply to count slashes.

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


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************



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