about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTanaka Akira <akr@users.sourceforge.net>2000-01-19 17:40:50 +0000
committerTanaka Akira <akr@users.sourceforge.net>2000-01-19 17:40:50 +0000
commitaf259b89dcf8d2ca74ebbb6cefb1db4de6336146 (patch)
tree81acc83d02c5925fecb4afc2cb8678bbde37700f
parent49ff05638b33ccf6a6531e141cbb55060caadbce (diff)
downloadzsh-af259b89dcf8d2ca74ebbb6cefb1db4de6336146.tar.gz
zsh-af259b89dcf8d2ca74ebbb6cefb1db4de6336146.tar.xz
zsh-af259b89dcf8d2ca74ebbb6cefb1db4de6336146.zip
zsh-workers/9371
-rw-r--r--Completion/Core/_files59
-rw-r--r--Completion/Core/_path_files14
-rw-r--r--Doc/Zsh/compsys.yo37
3 files changed, 95 insertions, 15 deletions
diff --git a/Completion/Core/_files b/Completion/Core/_files
index f3eb0e5fc..1b16f4e67 100644
--- a/Completion/Core/_files
+++ b/Completion/Core/_files
@@ -1,16 +1,19 @@
 #autoload
 
-local opts opt type=file glob group
+local opts opt type=file glob group gopts dopts aopts tmp _file_pat_checked=yes
 
 opts=()
 group=()
+gopts=()
+dopts=(-/)
+aopts=(-f)
 while getopts "P:S:qr:R:W:F:J:V:X:f/g:M:12n" opt; do
   case "$opt" in
-  /)      type="${type}dir"                   ;;
-  g)      type="${type}glob"; glob="$OPTARG"  ;;
-  [qn12]) opts=("$opts[@]" "-$opt"          ) ;;
-  [JV])   group=(          "-$opt" "$OPTARG") ;;
-  [^f])   opts=("$opts[@]" "-$opt" "$OPTARG") ;;
+  /)      type="${type}dir"                        ;;
+  g)      type="${type}glob"; gopts=(-g "$OPTARG") ;;
+  [qn12]) opts=("$opts[@]" "-$opt"          )      ;;
+  [JV])   group=(          "-$opt" "$OPTARG")      ;;
+  [^f])   opts=("$opts[@]" "-$opt" "$OPTARG")      ;;
   esac
 done
 
@@ -19,11 +22,37 @@ if [[ "$group[2]" = files ]]; then
   group=()
 fi
 
+if zstyle -s ":completion${curcontext}:all-files" file-patterns tmp &&
+   [[ -n "$tmp" ]]; then
+  aopts=(-g "$tmp")
+fi
+if zstyle -s ":completion${curcontext}:directories" file-patterns tmp &&
+   [[ -n "$tmp" ]]; then
+  dopts=(-g "$tmp")
+  if [[ "$type" = (*dir*glob*|*glob*dir*) ]]; then
+    type=glob
+  elif [[ "$type" != *(dir|glob)* ]]; then
+    type="${type}dir"
+  fi
+fi
+if zstyle -s ":completion${curcontext}:globbed-files" file-patterns tmp &&
+   [[ -n "$tmp" ]]; then
+  gopts=(-g "$tmp")
+  if [[ "$type" != (*dir*glob*|*glob*dir*) ]]; then
+    if [[ "$type" = *(dir|glob)* ]]; then
+      type=glob
+    else
+      type=globall
+    fi
+  fi
+fi
+
 case "$type" in
-*dir*glob*|*glob*dir) _tags globbed-files all-files             ;;
-*glob*)               _tags globbed-files directories all-files ;;
-*dir*)                _tags directories all-files               ;;
-*)                    _tags all-files                           ;;
+*dir*glob*|*glob*dir*) _tags globbed-files all-files             ;;
+*all*glob*|*glob*all*) _tags globbed-files all-files             ;;
+*glob*)                _tags globbed-files directories all-files ;;
+*dir*)                 _tags directories all-files               ;;
+*)                     _tags all-files                           ;;
 esac
 
 while _tags; do
@@ -32,7 +61,7 @@ while _tags; do
       group[2]=all-files
       _setup all-files
     fi
-    _path_files "$opts[@]" -f
+    _path_files "$opts[@]" "$aopts[@]"
     return
   elif _requested directories; then
     if _requested globbed-files; then
@@ -40,13 +69,13 @@ while _tags; do
         group[2]=globbed-files
 	_setup globbed-files
       fi
-      _path_files "$opts[@]" -/g "$glob" && return 0
+      _path_files "$opts[@]" "$dopts[@]" "$gopts[@]" && return 0
     else
       if (( $#group )); then
         group[2]=directories
 	_setup directories
       fi
-      _path_files "$opts[@]" -/ && return 0
+      _path_files "$opts[@]" "$dopts[@]" && return 0
     fi
   elif _requested globbed-files; then
     if (( $#group )); then
@@ -54,9 +83,9 @@ while _tags; do
       _setup globbed-files
     fi
     if [[ "$type" = (*dir*glob*|*glob*dir*) ]]; then
-      _path_files "$opts[@]" -/g "$glob" && return 0
+      _path_files "$opts[@]" "$dopts[@]" "$gopts[@]" && return 0
     else
-      _path_files "$opts[@]" -g "$glob" && return 0
+      _path_files "$opts[@]" "$gopts[@]" && return 0
     fi
   fi
 done
diff --git a/Completion/Core/_path_files b/Completion/Core/_path_files
index a53c5e10d..e76a54882 100644
--- a/Completion/Core/_path_files
+++ b/Completion/Core/_path_files
@@ -81,6 +81,20 @@ while getopts "P:S:qr:R:W:F:J:V:X:f/g:M:12n" opt; do
   esac
 done
 
+if [[ -z "$_file_pat_checked" ]] &&
+   zstyle -s ":completion${curcontext}:files" file-patterns tmp1 &&
+   [[ -n "$tmp1" ]]; then
+  if [[ "$tmp1" = '*(-/)' ]]; then
+    gopt=''
+    sopt=-/
+  else
+    gopt='-g'
+    sopt=-
+  fi
+  pats=( $=tmp1 )
+  haspats=yes
+fi
+
 if (( ! ( $#group + $#expl ) )); then
   if [[ -z "$gopt" && "$sopt" = -/ ]]; then
     _description directories expl directory
diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo
index fbe5ac265..863689afc 100644
--- a/Doc/Zsh/compsys.yo
+++ b/Doc/Zsh/compsys.yo
@@ -720,6 +720,39 @@ generated this way (e.g. due to the option tt(AUTO_MENU) being set),
 this will also cycle through the names of the files in pathname
 components after the first ambiguous one.
 )
+item(tt(file-patterns))(
+The completion system uses two functions to complete filenames,
+tt(_files) and tt(_path_files), with one of them calling the other,
+but this second one is sometimes also called directly. Depending on
+how it is called, the first one uses the tags tt(globbed-files),
+tt(directories) and tt(all-files). The second one, when called
+directly, uses the tag tt(files).
+
+Using this style one can specify which filenames should be completed
+in certain contexts. It is tested by tt(_files) and, if called
+directly, tt(_path_files) with the tags mentioned above. If it is set
+for these tags, the value is taken as a list of glob-patterns that
+should be used to select filenames when completing for the tag. Note
+that with tt(_files), calling completion function may specify that
+all files are to be completed. Normally this would make tt(_files) use 
+only the tt(all-files) tag, but if this style is set for any of the
+other two tags (tt(globbed-files) and tt(directories)), these tags
+will be used, too, in the normal order given above (unless the user
+specified another order to be used with the tt(tag-order) style).
+
+For example, to make the completion system first try only filenames
+matching the pattern tt(*.o) for the tt(rm) command, one would use:
+
+example(zstyle ':completion:*::rm*:globbed-files' file-patterns '*.o')
+
+With this, using only filenames ending in tt(.o) will be the first
+choice and other filenames will only be used if what is on the line
+matches none of the tt(.o) files (or if there are none).
+
+Note also that during the execution of completion functions, the
+tt(EXTENDED_GLOB) option is in effect, so the characters `tt(#)',
+`tt(~)' and `tt(^)' have special meanings in the patterns.
+)
 item(tt(format))(
 If this is set for the tt(descriptions) tag, its value is used as a
 string to display above matches in completion lists. The sequence
@@ -841,6 +874,10 @@ number of patterns. All matches that are matched by any of these
 patterns will be ignored as long as there are other matches not
 matched by any of the patterns.  It is a more configurable version
 of the shell parameter tt($fignore).
+
+Note that during the execution of completion functions, the
+tt(EXTENDED_GLOB) option is in effect, so the characters `tt(#)',
+`tt(~)' and `tt(^)' have special meanings in the patterns.
 )
 item(tt(insert-unambiguous))(
 This is used by the tt(_match) and tt(_approximate) completer