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

Re: [PATCH] Add option like tcsh's dextract



On 2023-08-09 09:24:53, Mikael Magnusson wrote:
The manpage entry says:
  This option makes tt(pushd) using `tt(PLUS())' or `tt(-)' behave
like tt(cd) with tt(AUTO_PUSHD) set.

This is true as I understand it, but it somewhat implies that pushd
without +/- acts differently from cd, so perhaps it should just say
"This option makes pushd behave like cd with AUTO_PUSHD set.", which
is also true but harder to misinterpret. (I wouldn't oppose keeping it
as it is, it's just something that tripped me up while reading it.)

I qualified this because pushd with no arguments _does_ act differently from cd. Pushd (without the pushd_to_home option set) swaps the top two directories on the stack, while cd always goes to the home directory, never swaps (with or without auto_pushd).

Maybe a better rewording is something like “cd using + or - always extracts from the directory stack, never rotates it, regardless of the setting of this option.” In this way pushd becomes the reference point for stack manipulation (as it should be), instead of cd. The previous wording more belongs in the Changelog, since it’s describing what behavior is new relative to existing, something that is unimportant to a user reading the man page.

Another thought I had was that perhaps with this option existing, the
behavior between cd and pushd need not be different at all anymore,
but maybe someone prefers being able to extract with cd and roll with
pushd, so probably not worth messing with that.

I personally don’t think that the + and - variants belong with cd at all, because with auto_pushd it’s too similar to pushd, and without auto_pushd the stack rearrangement doesn’t seem very intuitive or useful in either case (rotate or extract). Also the stack isn’t printed after the command. If you have a stack that looks like:

    dir1 dir2 dir3 dir4 dir5

Current behavior of “cd +2” doing extract without auto_pushd ends up with:

    dir3 dir2 dir4 dir5

A “cd +2” doing rotate without auto_pushd (not currently possible) might end up with:

    dir3 dir4 dir5 dir2

Of course, we’re stuck with it now, but zsh is the only shell that has this. Also, as you said, someone might want to be able to use both extract and rotate options.

It would also be unclear which way the default should be in that case...

I think unquestionably the default for pushd should be rotate, since all other shells that implement pushd (csh, tcsh, bash, and fish) rotate, with only tcsh providing the dextract option to switch to extract. If we were to implement a separate cd_extract option, I say it should be set by default, to match current behavior.

If the goal with this is to allow users to choose rotate or extract, we should also add command line options to override, which users can add to alias definitions.

I’m going to think about this some more. I’ve been working on a cd and pushd feature matrix for all the shells, which I’ll post later.

Tim



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