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

Re: cd bugs



On Tue, 14 Jul 2009 21:59:14 +0000 (UTC)
Eric Blake <ebb9@xxxxxxx> wrote:
> POSIX requires cd to give output if a nonempty entry in CDPATH played a
> role, or if 'cd -' was used.  Therefore, this line demonstrates two zsh
> bugs:
>
> $ zsh -c 'emulate -R sh; cd /tmp; mkdir -p d; CDPATH=.; cd d; cd -; rmdir d'
> $ bash -c 'cd /tmp; mkdir -p d; CDPATH=.; cd d; cd -; rmdir d'
> /tmp/d
> /tmp
> $
>
> while bash was correct in printing the absolute name of d and its parent.
>
> When fixing this, be sure that you don't break
>
> $ zsh -c 'emulate -R sh; mkdir foo; CDPATH=:; cd foo'
>
> since POSIX states that particular use must remain silent (an implicit . used
> from an empty CDPATH entry is different than an explicit . in CDPATH).

I think this should make the POSIX_CD option behave appropriately.

Index: Doc/Zsh/options.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/options.yo,v
retrieving revision 1.85
diff -u -r1.85 options.yo
--- Doc/Zsh/options.yo	19 Jul 2009 19:08:49 -0000	1.85
+++ Doc/Zsh/options.yo	21 Jul 2009 09:20:37 -0000
@@ -130,6 +130,14 @@
 If the option is set, the shell does not test for directories beneath
 the local directory (`tt(.)') until after all directories in tt(cdpath)
 have been tested.
+
+Also, if the option is set, the conditions under which the shell
+prints the new directory after changing to it are modified.  It is
+no longer restricted to interactive shells (although printing of
+the directory stack with tt(pushd) is still limited to interactive
+shells); and any use of a component of tt(CDPATH), including a `tt(.)' but
+excluding an empty component that is otherwise treated as `tt(.)', causes
+the directory to be printed.
 )
 pindex(PUSHD_IGNORE_DUPS)
 pindex(NO_PUSHD_IGNORE_DUPS)
Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.232
diff -u -r1.232 builtin.c
--- Src/builtin.c	19 Jul 2009 19:08:50 -0000	1.232
+++ Src/builtin.c	21 Jul 2009 09:20:37 -0000
@@ -972,8 +972,19 @@
     if (!nocdpath)
 	for (pp = cdpath; *pp; pp++) {
 	    if ((ret = cd_try_chdir(*pp, dest, hard))) {
-		if (strcmp(*pp, ".")) {
-		    doprintdir++;
+		if (isset(POSIXCD)) {
+		    /*
+		     * For POSIX we need to print the directory
+		     * any time CDPATH was used, except in the
+		     * special case of an empty segment being
+		     * treated as a ".".
+		     */
+		    if (**pp)
+			doprintdir++;
+		}  else {
+		    if (strcmp(*pp, ".")) {
+			doprintdir++;
+		    }
 		}
 		return ret;
 	    }
@@ -1146,8 +1157,8 @@
     pwd = new_pwd;
     set_pwd_env();
 
-    if (isset(INTERACTIVE)) {
-	if (func != BIN_CD) {
+    if (isset(INTERACTIVE) || isset(POSIXCD)) {
+	if (func != BIN_CD && isset(INTERACTIVE)) {
             if (unset(PUSHDSILENT) && !quiet)
 	        printdirstack();
         } else if (doprintdir) {


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


'member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom'



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