about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--Doc/Zsh/contrib.yo9
-rw-r--r--Functions/MIME/zsh-mime-handler23
3 files changed, 35 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 4c72e8cac..3326272f1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2006-08-09  Peter Stephenson  <pws@csr.com>
+
+	* 22593: Doc/Zsh/contrib.yo, Functions/MIME/zsh-mime-handler: add
+	handle-nonexistent style.
+
 2006-08-08  Peter Stephenson  <pws@csr.com>
 
 	* 22592: Functions/TCP/tcp_send, Doc/Zsh/tcpsys.yo: add tcp_send
diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo
index e86e28584..7d63378e3 100644
--- a/Doc/Zsh/contrib.yo
+++ b/Doc/Zsh/contrib.yo
@@ -1432,6 +1432,15 @@ item(tt(flags))(
 Defines flags to go with a handler; the context is as for the
 tt(handler) style, and the format is as for the flags in tt(mailcap).
 )
+item(tt(handle-nonexistent))(
+By default, arguments that don't correspond to files are not passed
+to the MIME handler in order to prevent it from intercepting commands found
+in the path that happen to have suffixes.  This style may be set to
+an array of extended glob patterns for arguments that will be passed to the
+handler even if they don't exist.  If it is not explicitly set it
+defaults to tt([[:alpha:]]:/*) which allows URLs to be passed to the MIME
+handler even though they don't exist in that format in the file system.
+)
 item(tt(handler))(
 Specifies a handler for a suffix; the suffix is given by the context as
 tt(:mime:.)var(suffix)tt(:), and the format of the handler is exactly
diff --git a/Functions/MIME/zsh-mime-handler b/Functions/MIME/zsh-mime-handler
index 52be70618..83df242af 100644
--- a/Functions/MIME/zsh-mime-handler
+++ b/Functions/MIME/zsh-mime-handler
@@ -48,7 +48,7 @@ suffix=$match[1]
 context=":mime:.${suffix}:"
 
 local handler flags no_sh no_bg
-local -a exec_asis
+local -a exec_asis hand_nonex
 
 # Set to a list of patterns which are ignored and executed as they are,
 # despite being called for interpretation by the mime handler.
@@ -56,6 +56,11 @@ local -a exec_asis
 # they are, even if they have a suffix.
 zstyle -a $context execute-as-is exec_asis || exec_asis=('*(*)' '*(/)')
 
+# Set to a list of patterns for which the handler will be used even
+# if the file doesn't exist on the disk.
+zstyle -a $context handle-nonexistent hand_nonex ||
+  hand_nonex=('[[:alpha:]]#:/*')
+
 local pattern
 local -a files
 
@@ -74,10 +79,24 @@ for pattern in $exec_asis; do
   files=(${dirpref}${~pattern})
   if [[ -n ${files[(r)$1]} ]]; then
     "$@"
-    return 0
+    return
   fi
 done
 
+if [[ ! -e $1 ]]; then
+  local nonex_ok
+  for pattern in $hand_nonex; do
+    if [[ $1 = ${~pattern} ]]; then
+      nonex_ok=1
+      break
+    fi
+  done
+  if [[ -z $nonex_ok ]]; then
+    "$@"
+    return
+  fi
+fi
+
 zstyle -s $context handler handler ||
   handler="${zsh_mime_handlers[$suffix]}"
 zstyle -s $context flags flags ||