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

Re: Cannot cd into --



On Fri, 29 Feb 2008 22:10:08 +0100
"Matthias B." <msbREMOVE-THIS@xxxxxxxxxxxxxxx> wrote:
> It doesn't seem to be possible with zsh to cd into a directory named --
> 
> cd -- -- 

That's a bug, but possible not as egregious as you think:  "cd --
-<number>" changes to an entry on the directory stack (and it's
special-cased so you don't need the leading "--").  There's no way
around that, so if the directory were called "-2" you'd still need to use
"./-2".  Here it was treating the second - as a truncated negative
number.  This just fixes cd---I'm not sure if the shell should ever
treat a - on its own in that fashion.

Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.187
diff -u -r1.187 builtin.c
--- Src/builtin.c	18 Feb 2008 03:18:03 -0000	1.187
+++ Src/builtin.c	2 Mar 2008 21:14:18 -0000
@@ -835,7 +835,8 @@
 	char *end;
 
 	doprintdir++;
-	if (argv[0][1] && (argv[0][0] == '+' || argv[0][0] == '-')) {
+	if (argv[0][1] && (argv[0][0] == '+' || argv[0][0] == '-')
+	    && strspn(argv[0]+1, "0123456789") == strlen(argv[0]+1)) {
 	    dd = zstrtol(argv[0] + 1, &end, 10);
 	    if (*end == '\0') {
 		if ((argv[0][0] == '+') ^ isset(PUSHDMINUS))


-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



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