From 0055b01bfa961d2cdf614e7361fb6eda53118c38 Mon Sep 17 00:00:00 2001 From: Matt Cable Date: Sat, 27 Feb 2010 16:15:47 -0700 Subject: [PATCH 01/10] Initial pass at pesistant directory stack --- lib/dirspersist.zsh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 lib/dirspersist.zsh diff --git a/lib/dirspersist.zsh b/lib/dirspersist.zsh new file mode 100644 index 0000000..a7c077a --- /dev/null +++ b/lib/dirspersist.zsh @@ -0,0 +1,19 @@ +#!/bin/zsh +# +# Make the dirstack more persistant +# +# Run dirpersiststore in ~/.zlogout + +dirpersiststore () { + dirs -p | sed 's/ /\\ /g;s/^/pushd -q /;1!G;h;$!d;' > ~/.zdirstore +} + +dirpersistrestore () { + if [ -f ~/.zdirstore ]; then + source ~/.zdirstore + fi +} + +DIRSTACKSIZE=10 +setopt autopushd pushdminus pushdsilent pushdtohome pushdignoredups +dirpersistrestore \ No newline at end of file From 751f34c9621fa08f909324a5367b0b4d8e2338e0 Mon Sep 17 00:00:00 2001 From: Matt Cable Date: Mon, 15 Mar 2010 20:34:26 -0600 Subject: [PATCH 02/10] Alias popd to remove deleted dirs from persistance --- lib/dirspersist.zsh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/dirspersist.zsh b/lib/dirspersist.zsh index a7c077a..8364a87 100644 --- a/lib/dirspersist.zsh +++ b/lib/dirspersist.zsh @@ -16,4 +16,7 @@ dirpersistrestore () { DIRSTACKSIZE=10 setopt autopushd pushdminus pushdsilent pushdtohome pushdignoredups -dirpersistrestore \ No newline at end of file +dirpersistrestore + +# Make popd changes permanent without having to wait for logout +alias popd="popd;dirpersiststore" \ No newline at end of file From 87920fb11177e37c6f16f441790605c762ce861d Mon Sep 17 00:00:00 2001 From: Matt Cable Date: Fri, 2 Apr 2010 15:24:41 -0600 Subject: [PATCH 03/10] Escape &'s in path name. Need to find general function for escaping all shell metacharacters. --- lib/dirspersist.zsh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/dirspersist.zsh b/lib/dirspersist.zsh index 8364a87..973107c 100644 --- a/lib/dirspersist.zsh +++ b/lib/dirspersist.zsh @@ -5,7 +5,8 @@ # Run dirpersiststore in ~/.zlogout dirpersiststore () { - dirs -p | sed 's/ /\\ /g;s/^/pushd -q /;1!G;h;$!d;' > ~/.zdirstore +# FIXME: need to escape all shell metacharacters, not just spaces! + dirs -p | sed 's/ /\\ /g;s/&/\\&/;s/^/pushd -q /;1!G;h;$!d;' > ~/.zdirstore } dirpersistrestore () { @@ -19,4 +20,4 @@ setopt autopushd pushdminus pushdsilent pushdtohome pushdignoredups dirpersistrestore # Make popd changes permanent without having to wait for logout -alias popd="popd;dirpersiststore" \ No newline at end of file +alias popd="popd;dirpersiststore" From faca005fe6682611273fd2769cd7a6d0a5c6706e Mon Sep 17 00:00:00 2001 From: Matt Cable Date: Thu, 22 Apr 2010 11:26:08 -0600 Subject: [PATCH 04/10] Escape some metachars that trip up .zdirstore script --- lib/dirspersist.zsh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/dirspersist.zsh b/lib/dirspersist.zsh index 973107c..d694c55 100644 --- a/lib/dirspersist.zsh +++ b/lib/dirspersist.zsh @@ -5,8 +5,7 @@ # Run dirpersiststore in ~/.zlogout dirpersiststore () { -# FIXME: need to escape all shell metacharacters, not just spaces! - dirs -p | sed 's/ /\\ /g;s/&/\\&/;s/^/pushd -q /;1!G;h;$!d;' > ~/.zdirstore + dirs -p | tail -r | perl -ne 'chomp;s/([& ])/\\$1/g ;print "if [ -d $_ ]; then pushd -q $_; fi\n"' > ~/.zdirstore } dirpersistrestore () { From daf855f2ed88bdbdc14e2bd63929966e93924db6 Mon Sep 17 00:00:00 2001 From: Matt Cable Date: Sun, 19 Sep 2010 19:39:51 -0600 Subject: [PATCH 05/10] Move dirpersist to plugin --- lib/dirspersist.zsh => plugins/dirpersist.plugin.zsh | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename lib/dirspersist.zsh => plugins/dirpersist.plugin.zsh (100%) diff --git a/lib/dirspersist.zsh b/plugins/dirpersist.plugin.zsh similarity index 100% rename from lib/dirspersist.zsh rename to plugins/dirpersist.plugin.zsh From e3e284016c8de8889150fa6f59f78bff93b14e83 Mon Sep 17 00:00:00 2001 From: Matt Cable Date: Sun, 19 Sep 2010 19:43:49 -0600 Subject: [PATCH 06/10] Added installation function --- plugins/dirpersist.plugin.zsh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/plugins/dirpersist.plugin.zsh b/plugins/dirpersist.plugin.zsh index d694c55..48ca94d 100644 --- a/plugins/dirpersist.plugin.zsh +++ b/plugins/dirpersist.plugin.zsh @@ -4,6 +4,17 @@ # # Run dirpersiststore in ~/.zlogout +dirpersistinstall () { + if grep -qL 'dirpersiststore' ~/.zlogout; then + else + 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\ndirpersiststore" >> ~/.zlogout + else + echo "If you don't want this message to appear, remove dirspersist from \$plugins" + fi + fi +} + dirpersiststore () { dirs -p | tail -r | perl -ne 'chomp;s/([& ])/\\$1/g ;print "if [ -d $_ ]; then pushd -q $_; fi\n"' > ~/.zdirstore } @@ -16,6 +27,8 @@ dirpersistrestore () { DIRSTACKSIZE=10 setopt autopushd pushdminus pushdsilent pushdtohome pushdignoredups + +dirpersistinstall dirpersistrestore # Make popd changes permanent without having to wait for logout From 515315e46773f160e6660e41c1e7a0c66186e785 Mon Sep 17 00:00:00 2001 From: Matt Cable Date: Sun, 19 Sep 2010 22:39:11 -0600 Subject: [PATCH 07/10] Added install instructions --- plugins/dirpersist.plugin.zsh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/dirpersist.plugin.zsh b/plugins/dirpersist.plugin.zsh index 48ca94d..4decd8b 100644 --- a/plugins/dirpersist.plugin.zsh +++ b/plugins/dirpersist.plugin.zsh @@ -2,7 +2,8 @@ # # Make the dirstack more persistant # -# Run dirpersiststore in ~/.zlogout +# Add dirpersist to $plugins in ~/.zshrc to load +# dirpersistinstall () { if grep -qL 'dirpersiststore' ~/.zlogout; then From 5539b3c72b4c38e382a89c633defd120901e3f47 Mon Sep 17 00:00:00 2001 From: Matt Cable Date: Sun, 19 Sep 2010 22:40:47 -0600 Subject: [PATCH 08/10] Change zdirstore to variable --- plugins/dirpersist.plugin.zsh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/plugins/dirpersist.plugin.zsh b/plugins/dirpersist.plugin.zsh index 4decd8b..5b3fdfb 100644 --- a/plugins/dirpersist.plugin.zsh +++ b/plugins/dirpersist.plugin.zsh @@ -5,6 +5,9 @@ # Add dirpersist to $plugins in ~/.zshrc to load # +# $zdirstore is the file used to persist the stack +zdirstore=~/.zdirstore + dirpersistinstall () { if grep -qL 'dirpersiststore' ~/.zlogout; then else @@ -17,12 +20,12 @@ dirpersistinstall () { } dirpersiststore () { - dirs -p | tail -r | perl -ne 'chomp;s/([& ])/\\$1/g ;print "if [ -d $_ ]; then pushd -q $_; fi\n"' > ~/.zdirstore + dirs -p | tail -r | perl -ne 'chomp;s/([& ])/\\$1/g ;print "if [ -d $_ ]; then pushd -q $_; fi\n"' > $zdirstore } dirpersistrestore () { - if [ -f ~/.zdirstore ]; then - source ~/.zdirstore + if [ -f $zdirstore ]; then + source $zdirstore fi } From f31b3728db40ca894bf190f451b4c505d6021569 Mon Sep 17 00:00:00 2001 From: Matt Cable Date: Tue, 21 Sep 2010 12:07:02 -0600 Subject: [PATCH 09/10] Removed unportable (and unnecessary) grep flags --- plugins/dirpersist.plugin.zsh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/dirpersist.plugin.zsh b/plugins/dirpersist.plugin.zsh index 5b3fdfb..b5e825b 100644 --- a/plugins/dirpersist.plugin.zsh +++ b/plugins/dirpersist.plugin.zsh @@ -9,7 +9,7 @@ zdirstore=~/.zdirstore dirpersistinstall () { - if grep -qL 'dirpersiststore' ~/.zlogout; then + if grep 'dirpersiststore' ~/.zlogout > /dev/null; then else 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\ndirpersiststore" >> ~/.zlogout @@ -19,6 +19,7 @@ dirpersistinstall () { fi } +# FIXME solaris doesn't support tail -r dirpersiststore () { dirs -p | tail -r | perl -ne 'chomp;s/([& ])/\\$1/g ;print "if [ -d $_ ]; then pushd -q $_; fi\n"' > $zdirstore } From 6fe935d59e08982fcb7652fe10cce8c3dec60abb Mon Sep 17 00:00:00 2001 From: Matt Cable Date: Sun, 26 Sep 2010 21:30:57 -0600 Subject: [PATCH 10/10] Portable perl dirpersiststore because 'tail -r' doesn't work everywhere. --- plugins/dirpersist.plugin.zsh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/dirpersist.plugin.zsh b/plugins/dirpersist.plugin.zsh index b5e825b..6a2b289 100644 --- a/plugins/dirpersist.plugin.zsh +++ b/plugins/dirpersist.plugin.zsh @@ -19,9 +19,8 @@ dirpersistinstall () { fi } -# FIXME solaris doesn't support tail -r dirpersiststore () { - dirs -p | tail -r | perl -ne 'chomp;s/([& ])/\\$1/g ;print "if [ -d $_ ]; then pushd -q $_; fi\n"' > $zdirstore + dirs -p | perl -e 'foreach (reverse ) {chomp;s/([& ])/\\$1/g ;print "if [ -d $_ ]; then pushd -q $_; fi\n"}' > $zdirstore } dirpersistrestore () {