summary refs log tree commit diff
path: root/Completion/Unix
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
parent17e576782c4fd64194d4908af5b9774308f1205f (diff)
downloadzsh-8c9a6b01d1bf727d27bc12d7e63fbb34fa157587.tar.gz
zsh-8c9a6b01d1bf727d27bc12d7e63fbb34fa157587.tar.xz
zsh-8c9a6b01d1bf727d27bc12d7e63fbb34fa157587.zip
20199: improve MIME handling.
Diffstat (limited to 'Completion/Unix')
-rw-r--r--Completion/Unix/Command/_elinks2
-rw-r--r--Completion/Unix/Type/.distfiles1
-rwxr-xr-xCompletion/Unix/Type/_mime_types42
3 files changed, 44 insertions, 1 deletions
diff --git a/Completion/Unix/Command/_elinks b/Completion/Unix/Command/_elinks
index 53e7b8ac8..615d9ba80 100644
--- a/Completion/Unix/Command/_elinks
+++ b/Completion/Unix/Command/_elinks
@@ -11,7 +11,7 @@ _arguments -C -A '-*' \
   '*-base-session[clone session with given ID]:ID number:' \
   '*-confdir[set config dir to given string]:configuration directory:_files -/' \
   '*-conffile[configuration file name]:configuration file:_files' \
-  '*-default-mime-type[MIME type to assume for documents]:MIME type:' \
+  '*-default-mime-type[MIME type to assume for documents]:MIME type:_mime_types' \
   '*-dump[write formatted version of given URL to stdout]::boolean:(0 1)' \
   '*-dump-charset[codepage to use with -dump]:codepage:' \
   '*-dump-width[width of document formatted with -dump]:width:' \
diff --git a/Completion/Unix/Type/.distfiles b/Completion/Unix/Type/.distfiles
index 5d4676bac..1392115dd 100644
--- a/Completion/Unix/Type/.distfiles
+++ b/Completion/Unix/Type/.distfiles
@@ -10,4 +10,5 @@ _groups              _perl_basepods       _signals             _users_on
 _hosts               _tar_archive         _time_zone
 _file_systems        _net_interfaces      _terminals           _locales
 _java_class          _services		  _email_addresses     _global_tags
+_mime_types
 '
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