about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--Completion/Base/Completer/_extensions33
-rw-r--r--Doc/Zsh/compsys.yo9
3 files changed, 45 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index af2fac8d2..806b14cc7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2014-03-03  Oliver Kiddle  <opk@zsh.org>
 
+	* 32441: Completion/Base/Completer/_extensions, Doc/Zsh/compsys.yo:
+	add completer for file extensions
+
 	* 32450: Src/Zle/zle_hist.c: make get-line set the history
 	number that was saved with the line
 
diff --git a/Completion/Base/Completer/_extensions b/Completion/Base/Completer/_extensions
new file mode 100644
index 000000000..8b6c4fd6a
--- /dev/null
+++ b/Completion/Base/Completer/_extensions
@@ -0,0 +1,33 @@
+#autoload
+
+# This completer completes filename extensions when completing
+# after *. or ^*. It can be used anywhere in the completer list
+# but if used after _expand, patterns that already match a file
+# will be expanded before it is called.
+
+compset -P '(#b)([~$][^/]#/|)(*/|)(\^|)\*.' || return 1
+
+local -aU files
+local -a expl suf mfiles
+
+files=( ${(e)~match[1]}${match[2]}*.* ) || return 1
+eval set -A files '${(MSI:'{1..${#${(O)files//[^.]/}[1]}}':)files%%.[^/]##}'
+files=( ${files:#.<->(.*|)} )
+
+if zstyle -t ":completion:${curcontext}:extensions" prefix-hidden; then
+  files=( ${files#.} )
+else
+  PREFIX=".$PREFIX"
+  IPREFIX="${IPREFIX%.}"
+fi
+
+zstyle -T ":completion:${curcontext}:extensions" add-space ||
+  suf=( -S '' )
+
+_description extensions expl 'file extension'
+
+# for an exact match, fail so as to give _expand or _match a chance.
+compadd -O mfiles "$expl[@]" -a files
+[[ $#mfiles -gt 1 || ${mfiles[1]} != $PREFIX ]] &&
+    compadd "$expl[@]" "$suf[@]" -a files &&
+    [[ -z $compstate[exact_string] ]]
diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo
index 5a5e61996..f015bbf92 100644
--- a/Doc/Zsh/compsys.yo
+++ b/Doc/Zsh/compsys.yo
@@ -3047,6 +3047,15 @@ This function is also a bindable command, see
 ifzman(the section `Bindable Commands' below)\
 ifnzman(noderef(Bindable Commands)).
 )
+findex(_extensions)
+item(tt(_extensions))(
+If the cursor follows the string `tt(*.)', filename extensions are
+completed. The extensions are taken from files in current directory or a
+directory specified at the beginning of the current word. For exact matches,
+completion continues to allow other completers such as tt(_expand) to
+expand the pattern. The standard tt(add-space) and tt(prefix-hidden)
+styles are observed.
+)
 findex(_history)
 item(tt(_history))(
 Complete words from the shell's command  history.  This completer