dirpersist.plugin.zsh
696 bytes
1# Save dirstack history to .zdirs
2# adapted from:
3# github.com/grml/grml-etc-core/blob/master/etc/zsh/zshrc#L1547
4
5DIRSTACKSIZE=${DIRSTACKSIZE:-20}
6dirstack_file=${dirstack_file:-${HOME}/.zdirs}
7
8if [[ -f ${dirstack_file} ]] && [[ ${#dirstack[*]} -eq 0 ]] ; then
9 dirstack=( ${(f)"$(< $dirstack_file)"} )
10 # "cd -" won't work after login by just setting $OLDPWD, so
11 [[ -d $dirstack[1] ]] && cd $dirstack[1] && cd $OLDPWD
12fi
13
14autoload -U add-zsh-hook
15add-zsh-hook chpwd chpwd_dirpersist
16chpwd_dirpersist() {
17 if (( $DIRSTACKSIZE <= 0 )) || [[ -z $dirstack_file ]]; then return; fi
18 local -ax my_stack
19 my_stack=( ${PWD} ${dirstack} )
20 builtin print -l ${(u)my_stack} >! ${dirstack_file}
21}