dirpersist.plugin.zsh 624 B

12345678910111213141516171819
  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() {
  12. if (( $DIRSTACKSIZE <= 0 )) || [[ -z $dirstack_file ]]; then return; fi
  13. local -ax my_stack
  14. my_stack=( ${PWD} ${dirstack} )
  15. builtin print -l ${(u)my_stack} >! ${dirstack_file}
  16. }