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

Re: persistent, shared directory stack possible?



Eric P. Mangold yazmış:
> Hi,
> 
> I'm looking for a way to transparently share a single directory stack
> between multiple instances of zsh in the same fashion as shared
> history.
> 
> I note the zsh-workers thread here which raises the same question:
> 
> http://www.zsh.org/mla/workers/2007/msg00691.html
> 
> Has anyone implemented this yet?

Here's a snippet from my zshrc which does it, not sure if it's perfect
though.

DIRSTACKSIZE=32
DIRSTACKFILE="${HOME}"/.zdirs

autoload -U is-at-least
# Keep dirstack across logouts
if [[ -f ${DIRSTACKFILE} ]] && [[ ${#dirstack[*]} -eq 0 ]] ; then
    dirstack=( ${(f)"$(< $DIRSTACKFILE)"} )
    dirstack=( ${(u)dirstack} )
fi

# Make sure there are no duplicates
typeset -U dirstack

# Share dirstack between multiple zsh instances
function chpwd() {
    if is-at-least 4.1; then # dirs -p needs 4.1
        # Get the dirstack from the file and add it to the current dirstack
        dirstack+=( ${(f)"$(< $DIRSTACKFILE)"} )
        dirstack=( ${(u)dirstack} )
        dirs -pl |sort -u >! ${DIRSTACKFILE}
    fi
}

> -teratorn
> 

-- 
Regards,
Ali Polatel

Attachment: pgpVMUEGM1kwM.pgp
Description: PGP signature



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