diff options
author | Peter Stephenson <pws@users.sourceforge.net> | 2010-07-20 18:59:15 +0000 |
---|---|---|
committer | Peter Stephenson <pws@users.sourceforge.net> | 2010-07-20 18:59:15 +0000 |
commit | c42ae31a190834df88af3339465e4ee2429b7592 (patch) | |
tree | 92f9307b5b76cae36cce58d07178db7fe6b7507b | |
parent | baee5347e4b099ae2306cd119cba4d5059b8b6f3 (diff) | |
download | zsh-c42ae31a190834df88af3339465e4ee2429b7592.tar.gz zsh-c42ae31a190834df88af3339465e4ee2429b7592.tar.xz zsh-c42ae31a190834df88af3339465e4ee2429b7592.zip |
28081: cdr tweaks
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | Doc/Zsh/contrib.yo | 18 | ||||
-rw-r--r-- | Functions/Chpwd/chpwd_recent_filehandler | 19 |
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 |