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

Re: dirstack-inheritance

On Oct 6, 11:53am, Johannes Mähner wrote:
} Subject: dirstack-inheritance
} Is there a way to inherit the directory stack in other zsh-sessions?
} (analogous mechanism as of command-history (incappendhistory,
} sharehistory) wanted)

You aren't actually suggesting that all the shells change current directory
in sync, are you?  I'm also uncertain what you think should happen in one
shell when another shell cycles its directory stack or swaps the top entry
with $PWD or the like.  The directory stack can change in a whole lot of
ways that history can't.  If one shell pops a directory out of the stack,
does it disappear from all the shells' stacks?  If not, and like history
you only share additions, when does the stack ever shrink?  (Arbitrarily
discard entries from the end when it exceeds a certain size?)

If you have 3.1.6-pws-6, you might be able to work something out using
`zmodload parameter' and then mucking with $dirstack.  If all you care
about is having a new shell start up with the same directory stack as the
most-recently-used shell, you can do put in .zshrc something like:

zmodload parameter && {
  [[ -f ~/.zdirs ]] && dirstack=( $(< ~/.zdirs) ) && popd
  precmd() {
    dirs >! ~/.zdirs

(The "popd" is because "dirs" is equivalent to "echo $PWD $dirstack".)

If you don't have 3.1.6-pws-6, you can do

dirstack=( $(< ~/.zdirs) )
cd $dirstack[-1]
while (($#dirstack)); do
  pushd $dirstack[-1]

Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

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