dirpersist.plugin.zsh 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/bin/zsh
  2. #
  3. # Make the dirstack more persistant
  4. #
  5. # Add dirpersist to $plugins in ~/.zshrc to load
  6. #
  7. # $zdirstore is the file used to persist the stack
  8. zdirstore=~/.zdirstore
  9. dirpersistinstall () {
  10. if grep 'dirpersiststore' ~/.zlogout > /dev/null; then
  11. else
  12. if read -q \?"Would you like to set up your .zlogout file for use with dirspersist? (y/n) "; then
  13. echo "# Store dirs stack\n# See $ZSH/plugins/dirspersist.plugin.zsh\ndirpersiststore" >> ~/.zlogout
  14. else
  15. echo "If you don't want this message to appear, remove dirspersist from \$plugins"
  16. fi
  17. fi
  18. }
  19. dirpersiststore () {
  20. dirs -p | perl -e 'foreach (reverse <STDIN>) {chomp;s/([& ])/\\$1/g ;print "if [ -d $_ ]; then pushd -q $_; fi\n"}' > $zdirstore
  21. }
  22. dirpersistrestore () {
  23. if [ -f $zdirstore ]; then
  24. source $zdirstore
  25. fi
  26. }
  27. DIRSTACKSIZE=10
  28. setopt autopushd pushdminus pushdsilent pushdtohome pushdignoredups
  29. dirpersistinstall
  30. dirpersistrestore
  31. # Make popd changes permanent without having to wait for logout
  32. alias popd="popd;dirpersiststore"