dirpersist.plugin.zsh 671 B

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