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

Re: persistant Directory history?



: On Mon, Nov 06, 2006 at 10:15PM +0530, chesss wrote:

> Basically I want to save the directory stack automatically and have
> ctrl+r like history..
> Possible?

I really wish the zsh-devs would include something for this in Zsh.
After I started having a persistent dirstack, I really had to wonder how
I had lived without it for so long :-)

Turns out there is a lot of people with custom ways to implement it.

[...]

As Stephane pointed out, all you need to do is to somehow set the
dirstack variable when you log in.

But I rather rewrite the zsh_dir_file everytime I change dirs. instead
of only after logout. Also (making a long story short) right after
login, just setting $OLDPWD won't allow you to use

% cd -

so I force the shell to visit the first dir in the stack to be able to
have this.

#-------------------------------------------------
# http://www.zsh.org/mla/users/2006/msg00173.html
# Adding a (rather primitive) dirstack history
DIRSTACKSIZE=20
if [[ -f ~/.zdirs ]] && [[ ${#dirstack[*]} -eq 0 ]]; then
    dirstack=( ${(uf)"$(< ~/.zdirs)"} )
    # "cd -" won't work after login by just setting $OLDPWD, so
    cd $dirstack[0] && cd - > /dev/null
fi
chpwd() { dirs -pl >! ~/.zdirs }
#-------------------------------------------------

My 2 cents on the topic....

Cheers,
-- 
Francisco Borges



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