about summary refs log tree commit diff
path: root/Completion/Base/Completer/_extensions
diff options
context:
space:
mode:
authorOliver Kiddle <opk@zsh.org>2014-03-03 16:50:14 +0100
committerOliver Kiddle <opk@zsh.org>2014-03-03 16:50:14 +0100
commit7d301a527e729e2a2fda03069e485bdcc2e12823 (patch)
tree363a583aecc48bccc7740c76794cafb85feefb3b /Completion/Base/Completer/_extensions
parentf62bd9c06c76b2b34a5e5454aa6f8617c7289b30 (diff)
downloadzsh-7d301a527e729e2a2fda03069e485bdcc2e12823.tar.gz
zsh-7d301a527e729e2a2fda03069e485bdcc2e12823.tar.xz
zsh-7d301a527e729e2a2fda03069e485bdcc2e12823.zip
32441: add completer for file extensions
Diffstat (limited to 'Completion/Base/Completer/_extensions')
-rw-r--r--Completion/Base/Completer/_extensions33
1 files changed, 33 insertions, 0 deletions
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] ]]