about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2012-08-21 18:45:31 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2012-08-21 18:45:31 +0000
commit76091a6995f7a567651232e2d164f6ea91462b05 (patch)
treeb3bc5d1256fed8f73ea7372d4e1dfd13734f17be
parent6f3ff6b653ca5e6f528bc46ec6295cb6d263a9fd (diff)
downloadzsh-76091a6995f7a567651232e2d164f6ea91462b05.tar.gz
zsh-76091a6995f7a567651232e2d164f6ea91462b05.tar.xz
zsh-76091a6995f7a567651232e2d164f6ea91462b05.zip
users/17211: new recursive-files style
-rw-r--r--ChangeLog5
-rw-r--r--Completion/Unix/Type/_files18
-rw-r--r--Doc/Zsh/compsys.yo22
3 files changed, 42 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 78e4f92f4..e4077cd1e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2012-08-21  Peter Stephenson  <p.w.stephenson@ntlworld.com>
 
+	* users/17211: Completion/Unix/Type/_files, Doc/Zsh/compsys.yo:
+	new recursive-files style.
+
 	* 30633: Doc/Zsh/builtins.yo, Src/builtin.c, Src/exec.c,
 	Src/hashtable.c, Src/options.c, Src/subst.c, Src/zsh.h:
 	"functions -T" traces only marked function and not called
@@ -95,5 +98,5 @@
 
 *****************************************************
 * This is used by the shell to define $ZSH_PATCHLEVEL
-* $Revision: 1.5705 $
+* $Revision: 1.5706 $
 *****************************************************
diff --git a/Completion/Unix/Type/_files b/Completion/Unix/Type/_files
index f21d7bc3b..0a2715814 100644
--- a/Completion/Unix/Type/_files
+++ b/Completion/Unix/Type/_files
@@ -1,7 +1,7 @@
 #compdef -redirect-,-default-,-default-
 
 local opts tmp glob pat pats expl tag i def descr end ign ret=1 match tried
-local type sdef ignvars ignvar
+local type sdef ignvars ignvar prepath oprefix rfiles rfile
 
 zparseopts -a opts \
     '/=tmp' 'f=tmp' 'g+:-=tmp' q n 1 2 P: S: r: R: W: X+: M+: F: J+: V+:
@@ -118,7 +118,21 @@ for def in "$pats[@]"; do
       while _next_label "$tag" expl "$descr"; do
         _comp_ignore=( $_comp_ignore $ign )
         if [[ -n "$end" ]]; then
-          _path_files -g "$pat" "$opts[@]" "$expl[@]" && ret=0
+          if _path_files -g "$pat" "$opts[@]" "$expl[@]"; then
+	    ret=0
+	  elif [[ $PREFIX$SUFFIX != */* ]] && zstyle -a ":completion:${curcontext}:$tag" recursive-files rfiles; then
+	    for rfile in $rfiles; do
+	      if [[ $PWD/ = ${~rfile} ]]; then
+		for prepath in **/*(/); do
+		  oprefix=$PREFIX
+		  PREFIX=$prepath/$PREFIX
+		  _path_files -g "$pat" "$opts[@]" "$expl[@]" && ret=0
+		  PREFIX=$oprefix
+		done
+		break
+	      fi
+	    done
+	  fi
         else
           _path_files "$expl[@]" -g "$pat" "$opts[@]" && ret=0
         fi
diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo
index 135a60a41..2787f66a7 100644
--- a/Doc/Zsh/compsys.yo
+++ b/Doc/Zsh/compsys.yo
@@ -2355,6 +2355,28 @@ found, or var(max) words have been tried.
 
 The default is to complete all words from the history at once.
 )
+kindex(recursive-files, completion style)
+item(tt(recursive-files))(
+If this style is set, its value is an array of patterns to be
+tested against `tt($PWD/)': note the trailing slash, which allows
+directories in the pattern to be delimited unambiguously by including
+slashes on both sides.  If an ordinary file completion fails
+and the word on the command line does not yet have a directory part to its
+name, the style is retrieved using the same tag as for the completion
+just attempted, then the elements tested against tt($PWD/) in turn.
+If one matches, then the shell reattempts completion by prepending the word
+on the command line with each directory in the expansion of tt(**/*(/))
+in turn.  Typically the elements of the style will be set to restrict
+the number of directories beneath the current one to a manageable
+number, for example `tt(*/.git/*)'.
+
+For example,
+
+example(zstyle ':completion:*' recursive-files '*/zsh/*')
+
+If the current directory is tt(/home/pws/zsh/Src), then
+tt(zle_tr)em(TAB) can be completed to tt(Zle/zle_tricky.c).
+)
 kindex(regular, completion style)
 item(tt(regular))(
 This style is used by the tt(_expand_alias) completer and bindable