zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-workers@sunsite.dk, 339635-forwarded@bugs.debian.org
Subject: Re: [ramk@cse.iitm.ernet.in: Bug#339635: zsh: zsh-mime-handler used even in the case of executable files]
Date: Thu, 6 Apr 2006 14:07:43 +0100	[thread overview]
Message-ID: <20060406140743.3819cb4e.pws@csr.com> (raw)

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


             reply	other threads:[~2006-04-06 13:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-06 13:07 Peter Stephenson [this message]
  -- strict thread matches above, loose matches on Subject: below --
2006-04-05 10:14 Peter Stephenson
2006-03-31 14:22 Clint Adams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060406140743.3819cb4e.pws@csr.com \
    --to=pws@csr.com \
    --cc=339635-forwarded@bugs.debian.org \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).