[IPython-dev] Changed dir stack implementation

Fernando Perez fperez.net at gmail.com
Sat Sep 8 21:12:01 EDT 2007

On 9/8/07, Ville M. Vainio <vivainio at gmail.com> wrote:
> The dir stack has apparently been broken for a while - it pushed the
> *target* directory, not the current directory as it should (which
> means it worked when you only moved around with pushd and popd, cwd
> was typically not pushed).

No, the brokennes is that the dirstack was starting empty.  Pushing
the target dir is the correct behavior, if we define 'correct' by the
30-year old behavior of pushd/popd/dirs in a *nix shell:

tlon[~]> dirs
tlon[~]> popd
popd: Directory stack empty.
tlon[~]> pushd ~/tmp
~/tmp ~
tlon[~/tmp]> pushd ~/talks
~/talks ~/tmp ~
tlon[~/talks]> popd
~/tmp ~

This is the behavior we must reproduce, else I'll go nuts (I'm used to
the *nix commands, as is probably anyone else who uses pushd/popd).

The trick is that the dir stack has a guard value, which the shell
always keeps synced to be $PWD:

tlon[~]> dirs
tlon[~]> popd
popd: Directory stack empty.
tlon[~]> cd tmp
tlon[~/tmp]> popd
popd: Directory stack empty.
tlon[~/tmp]> dirs
tlon[~/tmp]> cd ~/talks
tlon[~/talks]> dirs

In this case, let's just stick to the time-honored *nix convention
rather than inventing a new one, which will just confuse everybody.



More information about the IPython-dev mailing list