about summary refs log tree commit diff
path: root/Completion/Unix/Type/_mime_types
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2004-07-26 16:59:53 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2004-07-26 16:59:53 +0000
commit8c9a6b01d1bf727d27bc12d7e63fbb34fa157587 (patch)
tree3932e6e59f6b42c1b9be84c4b375c412c10a708a /Completion/Unix/Type/_mime_types
parent17e576782c4fd64194d4908af5b9774308f1205f (diff)
downloadzsh-8c9a6b01d1bf727d27bc12d7e63fbb34fa157587.tar.gz
zsh-8c9a6b01d1bf727d27bc12d7e63fbb34fa157587.tar.xz
zsh-8c9a6b01d1bf727d27bc12d7e63fbb34fa157587.zip
20199: improve MIME handling.
Diffstat (limited to 'Completion/Unix/Type/_mime_types')
-rwxr-xr-xCompletion/Unix/Type/_mime_types42
1 files changed, 42 insertions, 0 deletions
diff --git a/Completion/Unix/Type/_mime_types b/Completion/Unix/Type/_mime_types
new file mode 100755
index 000000000..1a967501c
--- /dev/null
+++ b/Completion/Unix/Type/_mime_types
@@ -0,0 +1,42 @@
+#autoload
+
+local expl maintype
+local -a default_type_files type_files match mbegin mend
+integer ind
+
+default_type_files=(~/.mime.types /etc/mime.types)
+
+# This is the same style as used by zsh-mime-setup, with a different
+# context.
+if zstyle -a ":completion:${curcontext}:mime" mime-types type_files; then
+  while (( (ind = ${type_files[(I)+]}) > 0 )); do
+    type_files[$ind]=($default_type_files)
+  done
+else
+  type_files=($default_type_files)
+fi
+
+#
+# Handle two different mime type formats; the simple
+# format:
+#   application/x-pws-frobnicate psf pwsf
+# and the extended format
+#   type=application/x-pws-frobnicate \
+#   desc="PWS frobnicated widget" \
+#   exts="pwsf,psf"
+# which Netscape seems to like.
+#
+
+if [[ $PREFIX = (#b)([^/]##)/* ]]; then
+  # Search for subtype.
+  maintype=$match[1]
+  compset -p $(( ${#maintype} + 1 ))
+  _wanted mimesubtype expl 'MIME subtype' \
+      compadd -- $(sed -ne "s%^\(type=\|\)${maintype}/\([^ 	]*\).*$%\2%p" \
+      $type_files)
+else
+  # Search for main type.
+  _wanted mimetype expl 'MIME type' \
+    compadd -S/ -- $(sed -ne "s/^type=//" \
+      -e "s%^\(${PREFIX:-[a-z]}[^=\"]*\)/.*$%\1%p" $type_files)
+fi