diff options
author | Peter Stephenson <pws@users.sourceforge.net> | 2010-07-09 14:47:48 +0000 |
---|---|---|
committer | Peter Stephenson <pws@users.sourceforge.net> | 2010-07-09 14:47:48 +0000 |
commit | 5da6530d831ea8a00943b39359d535ea59996894 (patch) | |
tree | 2a4fcd827214fa4fd2a8d172341a07cb8b76cda0 /Functions/Chpwd/chpwd_recent_filehandler | |
parent | 924f40b772d7c222ffe8db502fb88cc897fd9902 (diff) | |
download | zsh-5da6530d831ea8a00943b39359d535ea59996894.tar.gz zsh-5da6530d831ea8a00943b39359d535ea59996894.tar.xz zsh-5da6530d831ea8a00943b39359d535ea59996894.zip |
28065 plus unposted zsh.mdd:
add cdr and related functions and docs
Diffstat (limited to 'Functions/Chpwd/chpwd_recent_filehandler')
-rw-r--r-- | Functions/Chpwd/chpwd_recent_filehandler | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/Functions/Chpwd/chpwd_recent_filehandler b/Functions/Chpwd/chpwd_recent_filehandler new file mode 100644 index 000000000..b80e7f681 --- /dev/null +++ b/Functions/Chpwd/chpwd_recent_filehandler @@ -0,0 +1,42 @@ +# With arguments, output those files to the recent directory file. +# With no arguments, read in the directories from the file into $reply. +# +# Handles recent-dirs-file and recent-dirs-max styles. + +emulate -L zsh +setopt extendedglob + +integer max +local file +local -a files +local default=${ZDOTDIR:-$HOME}/.chpwd-recent-dirs + +if zstyle -a ':chpwd:' recent-dirs-file files; then + files=(${files//(#s)+(#e)/$default}) +fi +if (( ${#files} == 0 )); then + files=($default) +fi + +zstyle -s ':chpwd:' recent-dirs-max max || max=20 + +if (( $# )); then + if (( max > 0 && ${#argv} > max )); then + argv=(${argv[1,max]}) + fi + # Quote on write. + # Use $'...' quoting... this fixes newlines and other nastiness. + print -rl ${(qqqq)argv} >${files[1]} +else + typeset -g reply + # Unquote on read. + 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 + done +fi |