Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
Oh My Zsh
Commits
ef343eef
Commit
ef343eef
authored
Mar 20, 2014
by
Antoine Dechaume
Browse files
Fix dirpersist plugin
This plugin did not work, I just found the same functionnality in grml, this one works.
parent
ca900216
Changes
1
Hide whitespace changes
Inline
Side-by-side
plugins/dirpersist/dirpersist.plugin.zsh
View file @
ef343eef
#!/bin/zsh
# Save dirstack history to .zdirs
#
# adapted from:
# Make the dirstack more persistant
# github.com/grml/grml-etc-core/blob/master/etc/zsh/zshrc#L1547
#
# Add dirpersist to $plugins in ~/.zshrc to load
#
# $zdirstore is the file used to persist the stack
DIRSTACKSIZE
=
${
DIRSTACKSIZE
:-
20
}
z
dirst
ore
=
~
/.zdirs
tore
dirst
ack_file
=
${
dirstack_file
:-${
HOME
}
/.zdirs
}
dirpersistinstall
()
{
if
[[
-f
${
dirstack_file
}
]]
&&
[[
${#
dirstack
[*]
}
-eq
0
]]
;
then
if
grep
'dirpersiststore'
~/.zlogout
>
/dev/null
;
then
dirstack
=(
${
(f)
"
$(
<
$dirstack_file
)
"
}
)
else
# "cd -" won't work after login by just setting $OLDPWD, so
if
read
-q
\?
"Would you like to set up your .zlogout file for use with dirspersist? (y/n) "
;
then
[[
-d
$dirstack
[
1]
]]
&&
cd
$dirstack
[
1]
&&
cd
$OLDPWD
echo
"# Store dirs stack
\n
# See
$ZSH
/plugins/dirspersist.plugin.zsh
\n
dirpersiststore"
>>
~/.zlogout
fi
else
echo
"If you don't want this message to appear, remove dirspersist from
\$
plugins"
fi
fi
}
dirpersiststore
()
{
dirs
-p
| perl
-e
'foreach (reverse <STDIN>) {chomp;s/([& ])/\\$1/g ;print "if [ -d $_ ]; then pushd -q $_; fi\n"}'
>
$zdirstore
}
dirpersistrestore
()
{
chpwd
()
{
if
[
-f
$zdirstore
]
;
then
if
((
$DIRSTACKSIZE
<
=
0
))
||
[[
-z
$dirstack_file
]]
;
then return
;
fi
source
$zdirstore
local
-ax
my_stack
fi
my_stack
=(
${
PWD
}
${
dirstack
}
)
builtin
print
-l
${
(u)my_stack
}
>!
${
dirstack_file
}
}
}
DIRSTACKSIZE
=
10
setopt autopushd pushdminus pushdsilent pushdtohome pushdignoredups
dirpersistinstall
dirpersistrestore
# Make popd changes permanent without having to wait for logout
alias popd
=
"popd;dirpersiststore"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment