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

Re: pushd

On Oct 11,  2:34pm, Peter Stephenson wrote:
} Subject: pushd
} I know I'm several months behind everyone else, but I've belatedly
} realised that I find the new pushd behaviour unusable

Nevertheless, tcsh and bash behave the same way ...

} bring an arbitrary directory (say via pushd +2) to the top there's no
} way of knowing where in the stack the directory you were just in has
} landed.

Sure there is.  For `pushd +N', you can always get the original stack
ordering back with `pushd -(N-1)'.  It annoys me a little bit that using
`pushd -0' changes directory whereas `pushd +0' does not -- that is, I
think the current directory should be position zero in either direction,
not just when counting from the left -- but once again that's the way
that bash does it (tcsh doesn't accept `-N' at all).

(The above assumes, of course, that PUSHD_MINUS isn't set.)

} If I use `cd +2' the last directory disappears altogether.

I've always wondered whether the benefits of connecting `cd' to the
directory stack are worth it.  However, this is what I'd call the
expected behavior; you didn't ask for the current directory to be
put on the stack.

} (to put it another way, the
} behaviour pushing an existing directory when PUSHD_IGNORE_DUPS is set
} is now incompatible with pushd +n).

Ah, now that *is* a problem, because PUSHD_IGNORE_DUPS chops entries out
of the middle of the stack.  In that case you really do lose track of
where you are and where you came from.

Is the following more like the behavior you want?

function pushd() {
    setopt localoptions
    case $1 in
    +*) setopt pushdignoredups
	builtin pushd ${${=$(dirs)}[$1]} ;;
    -*) setopt pushdignoredups
	builtin pushd ${${=$(dirs)}[$1-1]} ;;
    *) builtin pushd $* ;;

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"

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