zsh-users
 help / color / mirror / code / Atom feed
* `popd' is blocked on non-existent directory
@ 1996-10-16  2:02 John S Cooper
  1996-10-16  5:26 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: John S Cooper @ 1996-10-16  2:02 UTC (permalink / raw)
  To: zsh-users; +Cc: john.cooper


Under zsh 3.0.0, if a directory in the directory stack is removed, popd
seems to get "blocked".  In 2.5, the non-existent directory would just be
removed from the stack.  Here's what happens:

1175 kontiki%> dirs -v                                                  ~/elisp
0       ~/elisp
1       ~/elisp/foo
2       ~/elisp/foo/tm
3       ~Sputnik/sdtmail
1176 kontiki%>                                                          ~/elisp
1176 kontiki%> popd                                                     ~/elisp
popd: no such file or directory: /space/jsc/elisp/foo
1177 kontiki%> dirs -v                                                  ~/elisp
0       ~/elisp
1       ~/elisp/foo
2       ~/elisp/foo/tm
3       ~Sputnik/sdtmail
1178 kontiki%>                                                          ~/elisp


I'm now unable to pop the stack back past the non-existent "~/elisp/foo"
directory.  I know I can `cd -3' but it would be much better to have the
non-existent stuff cleaned out of the stack.

Is there a way to get the old behavior, i.e. have all non-existent
directories removed from the stack?

Also, when there's only one entry left on the dir stack, (I think) a popd
used to remove it and pop me to my home directory.  This is no longer the
case in 3.0.0 .

Thanks,

    --- John.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: `popd' is blocked on non-existent directory
  1996-10-16  2:02 `popd' is blocked on non-existent directory John S Cooper
@ 1996-10-16  5:26 ` Bart Schaefer
  1996-10-17  0:56   ` John S Cooper
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 1996-10-16  5:26 UTC (permalink / raw)
  To: John S Cooper, zsh-users

On Oct 15,  7:02pm, John S Cooper wrote:
} Subject: `popd' is blocked on non-existent directory
}
} Under zsh 3.0.0, if a directory in the directory stack is removed, popd
} seems to get "blocked".  In 2.5, the non-existent directory would just be
} removed from the stack.
} 
} Is there a way to get the old behavior, i.e. have all non-existent
} directories removed from the stack?

--- Src/builtin.c.0	Tue Oct  8 10:30:08 1996
+++ Src/builtin.c	Tue Oct 15 21:23:49 1996
@@ -1082,6 +1082,8 @@
     if (!(dest = cd_do_chdir(nam, getdata(dir)))) {
 	if (!target)
 	    zsfree(getlinknode(dirstack));
+	if (func == BIN_POPD)
+	    zsfree(remnode(dirstack, dir));
 	return NULL;
     }
     if (dest != getdata(dir)) {

} Also, when there's only one entry left on the dir stack, (I think) a popd
} used to remove it and pop me to my home directory.  This is no longer the
} case in 3.0.0 .

The compatible-with-other-shells behavior in this case would be to issue a
`directory stack empty' error message.  (However, I could see an argument
that PUSHD_TO_HOME ought to apply to popd as well.)

What the code is actually doing is pushing the home directory onto the
stack (without actually doing the chdir) and then popping it back off
again.  Then it executes chdir to the top of the stack, that is, to the
directory it's already in:

zagzig[65] ./zsh -f
zagzig% chpwd() { echo CHPWD }
zagzig% popd
/usr/src/local/zsh/zsh-3.0.1-test3/Src
CHPWD
zagzig% popd
/usr/src/local/zsh/zsh-3.0.1-test3/Src
CHPWD

This seems like a lot of wasted effort, particularly considering that
chpwd gets run each time.

--- Src/builtin.c.0	Tue Oct  8 10:30:08 1996
+++ Src/builtin.c	Tue Oct 15 22:20:21 1996
@@ -1019,11 +1019,15 @@
     char *dest;
 
     if (!argv[0]) {
+	if (func == BIN_POPD && !nextnode(firstnode(dirstack))) {
+	    zwarnnam(nam, "directory stack empty", NULL, 0);
+	    return NULL;
+	}
 	if (func == BIN_PUSHD && unset(PUSHDTOHOME))
 	    dir = nextnode(firstnode(dirstack));
 	if (dir)
 	    insertlinknode(dirstack, dir, getlinknode(dirstack));
-	else
+	else if (func != BIN_POPD)
 	    pushnode(dirstack, ztrdup(home));
     } else if (!argv[1]) {
 	int dd;
@@ -1069,7 +1073,6 @@
     target = dir;
     if (func == BIN_POPD) {
 	if (!dir) {
-	    zsfree(getlinknode(dirstack));
 	    target = dir = firstnode(dirstack);
 	} else if (dir != firstnode(dirstack)) {
 	    return dir;

-- 
Bart Schaefer                             Brass Lantern Enterprises
http://www.well.com/user/barts            http://www.nbn.com/people/lantern

New male in /home/schaefer:
>N  2 Justin William Schaefer  Sat May 11 03:43  53/4040  "Happy Birthday"


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: `popd' is blocked on non-existent directory
  1996-10-16  5:26 ` Bart Schaefer
@ 1996-10-17  0:56   ` John S Cooper
  0 siblings, 0 replies; 3+ messages in thread
From: John S Cooper @ 1996-10-17  0:56 UTC (permalink / raw)
  To: schaefer; +Cc: John S Cooper, zsh-users

[-- Attachment #1: Type: text/plain, Size: 939 bytes --]

Bart Schaefer writes:
 > The compatible-with-other-shells behavior in this case would be to issue a
 > `directory stack empty' error message.  (However, I could see an argument
 > that PUSHD_TO_HOME ought to apply to popd as well.)

Thanks.  I've added a little code to do what you suggest and have popd also
honor the PUSHD_TO_HOME option.  Now, if you popd when there's a single
dirstack entry and PUSHD_TO_HOME is set, it'll pop you to your home
directory:

160 kontiki%> setopt pushdtohome 
162 kontiki%> dirs /usr/bin /tmp
163 kontiki%> dirs
~ /usr/bin /tmp
164 kontiki%> popd
/usr/bin /tmp
165 kontiki%> popd
/tmp
165 kontiki%> popd
~

.. and with pushdtohome unset:

156 kontiki%> unsetopt pushdtohome
157 kontiki%> dirs /usr/bin /tmp
158 kontiki%> dirs
~ /usr/bin /tmp
159 kontiki%> popd
/usr/bin /tmp
160 kontiki%> popd
/tmp
160 kontiki%> popd
popd: directory stack empty


I've attached the diffs (which include your changes):



[-- Attachment #2: Type: text/plain, Size: 1661 bytes --]

*** builtin.c	Wed Oct 16 17:31:48 1996
--- builtin.c.orig	Wed Oct 16 16:11:23 1996
***************
*** 998,1018 ****
      char *dest;
  
      if (!argv[0]) {
-         if (func == BIN_POPD && !nextnode(firstnode(dirstack))) {
-             if (unset(PUSHDTOHOME)) {
- 	        zwarnnam(nam, "directory stack empty", NULL, 0);
- 	        return NULL;
-             }
-             else {
-                 pushnode(dirstack, ztrdup(home));
-                 dir = nextnode(firstnode(dirstack));
-             }
-         }
  	if (func == BIN_PUSHD && unset(PUSHDTOHOME))
  	    dir = nextnode(firstnode(dirstack));
  	if (dir)
  	    insertlinknode(dirstack, dir, getlinknode(dirstack));
! 	else if (func != BIN_POPD)
  	    pushnode(dirstack, ztrdup(home));
      } else if (!argv[1]) {
  	int dd;
--- 998,1008 ----
      char *dest;
  
      if (!argv[0]) {
  	if (func == BIN_PUSHD && unset(PUSHDTOHOME))
  	    dir = nextnode(firstnode(dirstack));
  	if (dir)
  	    insertlinknode(dirstack, dir, getlinknode(dirstack));
! 	else
  	    pushnode(dirstack, ztrdup(home));
      } else if (!argv[1]) {
  	int dd;
***************
*** 1058,1063 ****
--- 1048,1054 ----
      target = dir;
      if (func == BIN_POPD) {
  	if (!dir) {
+ 	    zsfree(getlinknode(dirstack));
  	    target = dir = firstnode(dirstack);
  	} else if (dir != firstnode(dirstack)) {
  	    return dir;
***************
*** 1070,1077 ****
      if (!(dest = cd_do_chdir(nam, getdata(dir)))) {
  	if (!target)
  	    zsfree(getlinknode(dirstack));
- 	if (func == BIN_POPD)
- 	    zsfree(remnode(dirstack, dir));
  	return NULL;
      }
      if (dest != getdata(dir)) {
--- 1061,1066 ----

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1996-10-17  1:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-10-16  2:02 `popd' is blocked on non-existent directory John S Cooper
1996-10-16  5:26 ` Bart Schaefer
1996-10-17  0:56   ` John S Cooper

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).