Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [ramk@xxxxxxxxxxxxxxxxx: Bug#339635: zsh: zsh-mime-handler used even in the case of executable files]



Peter Stephenson <pws@xxxxxxx> wrote (about a patch from R. Ramkumar):
> +# Set to a list of patterns which are ignored and executed as they are,
> +# despite being called for interpretation by the mime handler.
> +# Defaults to executable files, which ensures that they are executed as
> +# they are, even if they have a suffix.
> +zstyle -a $context execute-as-is exec_asis || exec_asis=('*(*)')
> +
> +local pattern
> +
> +for pattern in $exec_asis; do
> +    if [[ $1 = ${~pattern} ]]; then
> +	"$@"
> +	return 0
> +    fi
> +done

... except on closer examination this doesn't work, since glob qualifiers
are only active for globbing.

This changes the test to use real globbing.  It'll fail if there are
directories in a pattern, but that's unlikely.  I haven't spotted
any other gotchas, yet.

Index: Functions/MIME/zsh-mime-handler
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/MIME/zsh-mime-handler,v
retrieving revision 1.5
diff -u -r1.5 zsh-mime-handler
--- Functions/MIME/zsh-mime-handler	5 Apr 2006 10:26:32 -0000	1.5
+++ Functions/MIME/zsh-mime-handler	6 Apr 2006 13:01:48 -0000
@@ -54,12 +54,25 @@
 zstyle -a $context execute-as-is exec_asis || exec_asis=('*(*)')
 
 local pattern
+local -a files
+
+# In case the pattern contains glob qualifiers, as it does by default,
+# we need to do real globbing, not just pattern matching.
+# The strategy is to glob the files in the directory using the
+# pattern and see if the one we've been passed is in the list.
+local dirpref=${1%/*}
+if [[ $dirpref = $1 ]]; then
+  dirpref=
+else
+  dirpref+=/
+fi
 
 for pattern in $exec_asis; do
-    if [[ $1 = ${~pattern} ]]; then
-	"$@"
-	return 0
-    fi
+  files=(${dirpref}${~pattern})
+  if [[ -n ${files[(r)$1]} ]]; then
+    "$@"
+    return 0
+  fi
 done
 
 zstyle -s $context handler handler ||

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php



Messages sorted by: Reverse Date, Date, Thread, Author