ef343eef307cf8d329240dcdf5e973f1d18d410e

Author
Antoine Dechaume <boolegue@gmail.com>
Committer
Antoine Dechaume <boolegue@gmail.com>
Date

Message

Fix dirpersist plugin

This plugin did not work, I just found the same functionnality in grml, this one works.

Diff

 1diff --git a/plugins/dirpersist/dirpersist.plugin.zsh b/plugins/dirpersist/dirpersist.plugin.zsh
 2index 0f6d9f435a5c318d6bd7674c4154d8ad9eb18184..88d1129d4ac9a21a0a08f1a61f6531b84f320c34 100644
 3--- a/plugins/dirpersist/dirpersist.plugin.zsh
 4+++ b/plugins/dirpersist/dirpersist.plugin.zsh
 5@@ -1,39 +1,19 @@
 6-#!/bin/zsh
 7-# 
 8-# Make the dirstack more persistant
 9-# 
10-# Add dirpersist to $plugins in ~/.zshrc to load
11-# 
12+# Save dirstack history to .zdirs
13+# adapted from:
14+# github.com/grml/grml-etc-core/blob/master/etc/zsh/zshrc#L1547
15 
16-# $zdirstore is the file used to persist the stack
17-zdirstore=~/.zdirstore
18+DIRSTACKSIZE=${DIRSTACKSIZE:-20}
19+dirstack_file=${dirstack_file:-${HOME}/.zdirs}
20 
21-dirpersistinstall () {
22-    if grep 'dirpersiststore' ~/.zlogout > /dev/null; then
23-    else
24-        if read -q \?"Would you like to set up your .zlogout file for use with dirspersist? (y/n) "; then
25-            echo "# Store dirs stack\n# See $ZSH/plugins/dirspersist.plugin.zsh\ndirpersiststore" >> ~/.zlogout
26-        else
27-            echo "If you don't want this message to appear, remove dirspersist from \$plugins"
28-        fi
29-    fi
30-}
31-
32-dirpersiststore () {
33-    dirs -p | perl -e 'foreach (reverse <STDIN>) {chomp;s/([& ])/\\$1/g ;print "if [ -d $_ ]; then pushd -q $_; fi\n"}' > $zdirstore
34-}
35+if [[ -f ${dirstack_file} ]] && [[ ${#dirstack[*]} -eq 0 ]] ; then
36+  dirstack=( ${(f)"$(< $dirstack_file)"} )
37+  # "cd -" won't work after login by just setting $OLDPWD, so
38+  [[ -d $dirstack[1] ]] && cd $dirstack[1] && cd $OLDPWD
39+fi
40 
41-dirpersistrestore () {
42-    if [ -f $zdirstore ]; then
43-        source $zdirstore
44-    fi
45+chpwd() {
46+  if (( $DIRSTACKSIZE <= 0 )) || [[ -z $dirstack_file ]]; then return; fi
47+  local -ax my_stack
48+  my_stack=( ${PWD} ${dirstack} )
49+  builtin print -l ${(u)my_stack} >! ${dirstack_file}
50 }
51-
52-DIRSTACKSIZE=10
53-setopt autopushd pushdminus pushdsilent pushdtohome pushdignoredups
54-
55-dirpersistinstall
56-dirpersistrestore
57-
58-# Make popd changes permanent without having to wait for logout
59-alias popd="popd;dirpersiststore"