zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-workers@sunsite.dk
Subject: Re: cd bugs
Date: Tue, 21 Jul 2009 10:22:53 +0100	[thread overview]
Message-ID: <20090721102253.7a6496da@news01> (raw)
In-Reply-To: <loom.20090714T205419-391@post.gmane.org>

On Tue, 14 Jul 2009 21:59:14 +0000 (UTC)
Eric Blake <ebb9@byu.net> 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@csr.com>            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'


      parent reply	other threads:[~2009-07-21  9:30 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-14 21:59 Eric Blake
2009-07-14 22:30 ` Eric Blake
2009-07-19 19:00   ` Peter Stephenson
2009-07-15  3:28 ` Eric Blake
2009-07-15  8:45   ` Peter Stephenson
2009-07-21  9:22 ` Peter Stephenson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090721102253.7a6496da@news01 \
    --to=pws@csr.com \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).