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