prezto/plugins/dirpersist/init.zsh

37 lines
1 KiB
Bash
Raw Normal View History

#!/bin/zsh
2011-08-30 23:16:15 -04:00
# Makes the dirstack more persistant.
2010-09-19 22:40:47 -06:00
2011-08-30 23:16:15 -04:00
# $zdirstore is the file used to persist the stack.
zdirstore="$HOME/.zdirstore"
function dirpersist-install() {
if ! grep 'dirpersist-store' "$HOME/.zlogout" 2> /dev/null; then
if read -q \?"Would you like to set up your .zlogout file for use with dirspersist? (y/n) "; then
echo "# Store dirs stack\n# See ~/.oh-my-zsh/plugins/dirspersist.plugin.zsh\ndirpersist-store" >>! "$HOME/.zlogout"
2010-09-19 19:43:49 -06:00
else
2011-08-30 23:16:15 -04:00
echo "\nIf you don't want this message to appear, remove dirspersist from \$plugins."
2010-09-19 19:43:49 -06:00
fi
2011-08-30 23:16:15 -04:00
fi
2010-09-19 19:43:49 -06:00
}
2011-08-30 23:16:15 -04:00
function dirpersist-store() {
dirs -p | perl -e 'foreach (reverse <STDIN>) {chomp;s/([& ])/\\$1/g ;print "if [ -d $_ ]; then pushd -q $_; fi\n"}' > "$zdirstore"
}
2011-08-30 23:16:15 -04:00
function dirpersist-restore() {
if [[ -f "$zdirstore" ]]; then
source "$zdirstore"
fi
}
DIRSTACKSIZE=10
setopt autopushd pushdminus pushdsilent pushdtohome pushdignoredups
2010-09-19 19:43:49 -06:00
2011-08-30 23:16:15 -04:00
dirpersist-install
dirpersist-restore
# Make popd changes permanent without having to wait for logout
2011-08-30 23:16:15 -04:00
alias popd="popd;dirpersist-store"