]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/dirpersist/dirpersist.plugin.zsh
initial
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / plugins / dirpersist / dirpersist.plugin.zsh
1 # Save dirstack history to .zdirs
2 # adapted from:
3 # github.com/grml/grml-etc-core/blob/master/etc/zsh/zshrc#L1547
4
5 DIRSTACKSIZE=${DIRSTACKSIZE:-20}
6 dirstack_file=${dirstack_file:-${HOME}/.zdirs}
7
8 if [[ -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
12 fi
13
14 autoload -U add-zsh-hook
15 add-zsh-hook chpwd chpwd_dirpersist
16 chpwd_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 }