zsh-workers
 help / color / mirror / code / Atom feed
* Recent directory tweaks
@ 2010-07-15 20:26 Peter Stephenson
  2010-07-20 19:03 ` Peter Stephenson
  0 siblings, 1 reply; 2+ messages in thread
From: Peter Stephenson @ 2010-07-15 20:26 UTC (permalink / raw)
  To: Zsh hackers list

A couple of tweaks to this before I finally make a release.

Point out in the documentation for people who aren't hardcore completion
system users that it's possible to get a different set of recent
directories in different locations.  Actually, I think this gets
polluted by the handling for $OLDPWD in chpwd_recent_dirs, i.e. the
directory you've come from may get added even if, if you were in it,
you'd use a different file, but I'll look at that another time.

Make the file handler future-proofer by ignoring any trailing stuff
on each line in the recent directories file.  There's nothing there at
the moment, but one day it might be worth saving timestamps or other
information.

Index: Doc/Zsh/contrib.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/contrib.yo,v
retrieving revision 1.120
diff -p -u -r1.120 contrib.yo
--- Doc/Zsh/contrib.yo	12 Jul 2010 09:57:14 -0000	1.120
+++ Doc/Zsh/contrib.yo	15 Jul 2010 20:19:13 -0000
@@ -453,12 +453,28 @@ are shown first.  The special value tt(+
 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
Index: Functions/Chpwd/chpwd_recent_filehandler
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/Chpwd/chpwd_recent_filehandler,v
retrieving revision 1.1
diff -p -u -r1.1 chpwd_recent_filehandler
--- Functions/Chpwd/chpwd_recent_filehandler	9 Jul 2010 14:47:48 -0000	1.1
+++ Functions/Chpwd/chpwd_recent_filehandler	15 Jul 2010 20:19:13 -0000
@@ -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


-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Recent directory tweaks
  2010-07-15 20:26 Recent directory tweaks Peter Stephenson
@ 2010-07-20 19:03 ` Peter Stephenson
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 2010-07-20 19:03 UTC (permalink / raw)
  To: Zsh hackers list

On Thu, 15 Jul 2010 21:26:05 +0100
Peter Stephenson <p.w.stephenson@ntlworld.com> wrote:
> Point out in the documentation for people who aren't hardcore completion
> system users that it's possible to get a different set of recent
> directories in different locations.  Actually, I think this gets
> polluted by the handling for $OLDPWD in chpwd_recent_dirs, i.e. the
> directory you've come from may get added even if, if you were in it,
> you'd use a different file, but I'll look at that another time.

I think the answer is that's an unnecessary complexity anyway.  It's
enough to record directories you actually changed to, not ones you've
come from.  Most of the time this just means you don't put ~ in the list
when the shell started there.  I think.

Index: Functions/Chpwd/chpwd_recent_dirs
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/Chpwd/chpwd_recent_dirs,v
retrieving revision 1.1
diff -p -u -r1.1 chpwd_recent_dirs
--- Functions/Chpwd/chpwd_recent_dirs	9 Jul 2010 14:47:48 -0000	1.1
+++ Functions/Chpwd/chpwd_recent_dirs	20 Jul 2010 19:00:21 -0000
@@ -38,11 +38,6 @@ fi
 chpwd_recent_filehandler
 
 if [[ $reply[1] != $PWD ]]; then
-  if [[ -n $OLDPWD && $reply[1] != $OLDPWD ]]; then
-    # The first time we change directory we probably don't have
-    # the initial directory.
-    chpwd_recent_add $OLDPWD && changed=1
-  fi
   chpwd_recent_add $PWD && changed=1
 
   (( changed )) && chpwd_recent_filehandler $reply

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-07-20 19:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-15 20:26 Recent directory tweaks Peter Stephenson
2010-07-20 19:03 ` Peter Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).