From a0a8ba666b29cbcdbba05726e4e2d46eca708ca1 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 00000000..a7c077ae --- /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 870551e960c6cb506fd7cc232a069432dfc72f2c 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 a7c077ae..8364a879 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 21e2a913bff765b8dc23f12309059f7446e0ff99 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 8364a879..973107c5 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 181a2ed5379f5bf9d0420c0caaea56034eb22732 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 973107c5..d694c55e 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 50fb2d037ee75ac6e558923c7a92c818a96d43c8 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 1862b1c0755770cffcbcb936bdecc3bfb050931d 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 d694c55e..48ca94d7 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 610f68c8e0401048f87d1f2bd48086b8c0cd0dbe 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 48ca94d7..4decd8b3 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 8f7609b4fabd3d02e3991221cbe35bea692c22e3 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 4decd8b3..5b3fdfb3 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 2ff567e16267274041f542b5bce18876b8815fca 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 5b3fdfb3..b5e825bf 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 3add6a2ac47186240a2d02a986ae22b6519d965f 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 b5e825bf..6a2b289a 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 () {