zsh-workers
 help / color / mirror / code / Atom feed
* Re: [ramk@cse.iitm.ernet.in: Bug#339635: zsh: zsh-mime-handler used even in the case of executable files]
@ 2006-04-05 10:14 Peter Stephenson
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 2006-04-05 10:14 UTC (permalink / raw)
  To: zsh-workers, 339635-forwarded

Clint Adams <schizo@debian.org> wrote:
> From: "R.Ramkumar" <ramk@cse.iitm.ernet.in>
> 
> 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.
 )
+item(tt(execute-as-is))(
+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.
+)
 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).
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 @@
 context=":mime:.${suffix}:"
 
 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
+done
 
 zstyle -s $context handler handler ||
   handler="${zsh_mime_handlers[$suffix]}"

-- 
Peter Stephenson <pws@csr.com>                  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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [ramk@cse.iitm.ernet.in: Bug#339635: zsh: zsh-mime-handler used even in the case of executable files]
@ 2006-04-06 13:07 Peter Stephenson
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 2006-04-06 13:07 UTC (permalink / raw)
  To: zsh-workers, 339635-forwarded

Peter Stephenson <pws@csr.com> 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@csr.com>                  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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ramk@cse.iitm.ernet.in: Bug#339635: zsh: zsh-mime-handler used even in the case of executable files]
@ 2006-03-31 14:22 Clint Adams
  0 siblings, 0 replies; 3+ messages in thread
From: Clint Adams @ 2006-03-31 14:22 UTC (permalink / raw)
  To: zsh-workers; +Cc: 339635-forwarded

Another patch from R.Ramkumar for which I hold no opinion.

----- Forwarded message from "R.Ramkumar" <ramk@cse.iitm.ernet.in> -----

Date: Thu, 17 Nov 2005 23:34:25 +0530
From: "R.Ramkumar" <ramk@cse.iitm.ernet.in>
To: Debian Bug Tracking System <submit@bugs.debian.org>
Subject: Bug#339635: zsh: zsh-mime-handler used even in the case of executable files

Package: zsh
Version: 4.2.5-22
Severity: wishlist
Tags: patch

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.




Content-Description: Patch for the execute-as-is style to zsh-mime-handler
--- zsh-mime-handler.orig	2005-11-17 23:21:14.000000000 +0530
+++ zsh-mime-handler	2005-11-17 23:31:37.000000000 +0530
@@ -45,6 +45,22 @@
 context=":mime:.${suffix}:"
 
 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
+done
 
 zstyle -s $context handler handler ||
   handler="${zsh_mime_handlers[$suffix]}"


Hope this helps :)

Regards,
Ramkumar

-- System Information:
Debian Release: testing/unstable
  APT prefers testing
  APT policy: (101, 'testing')
Architecture: i386 (i686)
Shell:  /bin/sh linked to /bin/dash
Kernel: Linux 2.6.14-archck1
Locale: LANG=en_IN, LC_CTYPE=en_IN (charmap=UTF-8)

Versions of packages zsh depends on:
ii  debconf [debconf-2.0]         1.4.58     Debian configuration management sy
ii  libc6                         2.3.5-6    GNU C Library: Shared libraries an
ii  libncurses5                   5.4-9      Shared libraries for terminal hand

Versions of packages zsh recommends:
ii  libcap1                       1:1.10-14  support for getting/setting POSIX.
ii  libpcre3                      6.4-1.0.1  Perl 5 Compatible Regular Expressi

-- no debconf information

-- 
WARN_(accel)("msg null; should hang here to be win compatible\n");
                                   -- WINE source code


----- End forwarded message -----


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-04-06 13:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-04-05 10:14 [ramk@cse.iitm.ernet.in: Bug#339635: zsh: zsh-mime-handler used even in the case of executable files] Peter Stephenson
  -- strict thread matches above, loose matches on Subject: below --
2006-04-06 13:07 Peter Stephenson
2006-03-31 14:22 Clint Adams

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).