Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Recent directory tweaks
- X-seq: zsh-workers 28081
- From: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx (Zsh hackers list)
- Subject: Recent directory tweaks
- Date: Thu, 15 Jul 2010 21:26:05 +0100
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
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@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/
Messages sorted by:
Reverse Date,
Date,
Thread,
Author