summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog10
-rw-r--r--Doc/Zsh/contrib.yo18
-rw-r--r--Functions/Chpwd/chpwd_recent_filehandler19
3 files changed, 37 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index 952723d9b..2d9059d2e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,12 @@
+2010-07-20  Peter Stephenson  <p.w.stephenson@ntlworld.com>
+
+	* 28081: Doc/Zsh/contrib.yo,
+	Functions/Chpwd/chpwd_recent_filehandler: document style
+	stuff with cdr, future-proof file reading.
+
 2010-07-19  Peter Stephenson  <pws@csr.com>
 
-	* Completion/Unix/Command/_getconf: generate missing keys.
+	* 28092: Completion/Unix/Command/_getconf: generate missing keys.
 
 2010-07-19  Frank Terbeck  <ft@bewatermyfriend.org>
 
@@ -13395,5 +13401,5 @@
 
 *****************************************************
 * This is used by the shell to define $ZSH_PATCHLEVEL
-* $Revision: 1.5030 $
+* $Revision: 1.5031 $
 *****************************************************
diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo
index ca00ad118..e33ac9b9e 100644
--- a/Doc/Zsh/contrib.yo
+++ b/Doc/Zsh/contrib.yo
@@ -453,12 +453,28 @@ are shown first.  The special value tt(+) can appear in the list to
 indicate the default file should be read at that point.  This allows
 effects like the following:
 
-example(zstyle recent-dirs-file ':chpwd:*' \ 
+example(zstyle ':chpwd:*' recent-dirs-file \ 
 ~/.chpwd-recent-dirs-${TTY##*/} +)
 
 Recent directories are read from a file numbered according to
 the terminal.  If there are insufficient entries the list
 is supplemented from the default file.
+
+It is possible to use tt(zstyle -e) to make the directory configurable
+at run time:
+
+example(zstyle -e ':chpwd:*' recent-dirs-file pick-recent-dirs-file
+pick-recent-dirs-file() {
+  if [[ $PWD = ~/text/writing(|/*) ]]; then
+    reply=(~/.chpwd-recent-dirs-writing)
+  else
+    reply=(+)
+  fi
+})
+
+In this example, if the current directory is tt(~/text/writing) or a
+directory under it, then use a special file for saving recent
+directories, else use the default.
 )
 item(tt(recent-dirs-insert))(
 Used by completion.  If tt(recent-dirs-default) is true, then setting
diff --git a/Functions/Chpwd/chpwd_recent_filehandler b/Functions/Chpwd/chpwd_recent_filehandler
index b80e7f681..688612be7 100644
--- a/Functions/Chpwd/chpwd_recent_filehandler
+++ b/Functions/Chpwd/chpwd_recent_filehandler
@@ -7,8 +7,8 @@ emulate -L zsh
 setopt extendedglob
 
 integer max
-local file
-local -a files
+local file line
+local -a files dir
 local default=${ZDOTDIR:-$HOME}/.chpwd-recent-dirs
 
 if zstyle -a ':chpwd:' recent-dirs-file files; then
@@ -33,10 +33,15 @@ else
   reply=()
   for file in $files; do
     [[ -r $file ]] || continue
-    reply+=(${(Q)${(f)"$(<$file)"}})
-    if (( max > 0 && ${#reply} >= max )); then
-      reply=(${reply[1,max]})
-      break
-    fi
+    # Strip anything after the directory from the line.
+    # At the moment there isn't anything, but we'll make this
+    # future proof.
+    for line in ${(f)"$(<$file)"}; do
+      dir=(${(z)line})
+      reply+=(${(Q)${dir[1]}})
+      if (( max > 0 && ${#reply} == max )); then
+	break 2
+      fi
+    done
   done
 fi