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]

Clint Adams <schizo@xxxxxxxxxx> wrote:
> From: "R.Ramkumar" <ramk@xxxxxxxxxxxxxxxxx>
> Some scripts end with a .sh (a common example being autogen.sh). For
> such scripts, zsh-mime-handler ends up executing the mime action for
> the suffix sh, which sometimes happens to be to just display the
> file. This, I guess is due to alias -s, which blindly maps in case
> the suffix matches. To counter this, it would be good if
> zsh-mime-handler uses a style to take a set of patterns that would
> be executed as-is, despite having a suffix found in the mime
> configuration. I am enclosing a patch for the same. I have made the
> set of executable files as the default for this style, I hope this
> deviation from the original behaviour is acceptable.

The change from the original behaviour seems sensible.

I'll commit this with the following documentation.  I've also turned $@
into "$@" in zsh-mime-handler.

Index: Doc/Zsh/contrib.yo
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/contrib.yo,v
retrieving revision 1.55
diff -u -r1.55 contrib.yo
--- Doc/Zsh/contrib.yo	20 Mar 2006 11:06:25 -0000	1.55
+++ Doc/Zsh/contrib.yo	5 Apr 2006 10:12:20 -0000
@@ -1391,6 +1391,15 @@
 tt(sh) process.  This is more efficient, but may not work in the occasional
 cases where the mailcap handler uses strict POSIX syntax.
+This style gives a list of patterns to be matched against files
+passed for execution with a handler program.  If the file matches
+the pattern, the entire command line is executed in its current form,
+with no handler.  This is useful for files which might have suffixes
+but nonetheless be executable in their own right.  If the style
+is not set, the pattern tt(*+LPAR()*+RPAR()) is used; hence executable
+files are executed directly and not passed to a handler.
 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).
Index: Functions/MIME/zsh-mime-handler
RCS file: /cvsroot/zsh/zsh/Functions/MIME/zsh-mime-handler,v
retrieving revision 1.4
diff -u -r1.4 zsh-mime-handler
--- Functions/MIME/zsh-mime-handler	28 Feb 2006 11:57:20 -0000	1.4
+++ Functions/MIME/zsh-mime-handler	5 Apr 2006 10:12:20 -0000
@@ -45,6 +45,22 @@
 local handler flags no_sh no_bg
+local -a exec_asis
+# 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
 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