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

Re: pushd



Bart wrote:
> } I have to say, the cd functions are a real mess.
> 
> There are several confusing things here.  (1) The current directory isn't
> kept on the stack (so the stack really is empty if you've never pushd'd);
> but (2) the first thing bin_cd() does is put the current directory on the
> stack; so (3) none of the functions that manipulate the stack ever see it
> in empty state, *except* (4) bin_dirs(), printdirstack(), and dstackent()
> [in subst.c], which all have to special case ~0 as equivalent to $PWD; and
> (5) all of this means that cd_new_pwd() and/or bin_cd() have to discard
> the top of the stack once the other routines are finished.
> 
> Add to this the ability to shovel random tripe into the stack with:
> [...] 
> and I agree you have a bit of a mess.

Hmmph.  I guess I'm not supposed to take that personally. :-)

Seriously, the explanation above is exactly right, and I don't think
it's as messy as all that -- it's just not documented or restructured.
And BTW the reason that it's not documented is that RC didn't want to
incorporate any of the versions of this patch that I produced, so I tried
to keep the patch as small as possible so that it wouldn't cause Zoltan
too much trouble in maintaining his releases.  But once you've got the
hang of the fact that $PWD is pushed onto the stack, the rest follows. And
pushing $PWD is a good idea, since you might be executing pushd, or have
AUTOPUSHD set, or whatever, and you don't need to specialcase.

But Bart's changes to popd make complete sense -- in retrospect I've no
idea why I didn't do the obvious optimisation.

I'm still puzzled, though, as to why Peter et al want this PUSHD_CYCLE option.
The reason it's so easy to implement is that it is, in effect, simply
aliasing pushd=cd.  Completely altering the de-facto standard definition of a
shell command is something on balance to be avoided.  To repeat my suggestion,
why not just make cd +n push the current directory?  Then it'll do exactly
the same as pushd, while being two less chars to type, and not requiring
extra emulation parameters.

Anthony



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