From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29356 invoked by alias); 8 Sep 2013 18:24:45 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 31711 Received: (qmail 20922 invoked from network); 8 Sep 2013 18:24:30 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 Received-SPF: neutral (ns1.primenet.com.au: 209.85.215.169 is neither permitted nor denied by SPF record at ntlworld.com) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-type:content-transfer-encoding; bh=+7gwKNHPmyo6RFtw2rO0Fu5JXaeQrY6+irK+UcD3NhE=; b=M2CQCZSBuVX1Bzkyw2XSxRIHgEHz+Q/dBGQK7uQhtf+eMHIRTSzQF+bYUOWZNPx58W ngYSgJ6wp8imY1Uj9W84s6LAqNzq0R8Ypl96jrxWEqML3BDPDjYwlgACKDe36FpPbkxX VUDPSUW+KZsEVKj30szITnevtj2aAhBZ124VLOzmN6KOzKCzvoyB4CXWFX3Ids3aFTkz OwIGh86VXhvXjUcE1ujSj6BGycUkmSAlAWa6wTnLIwed2K8UrHpNZkgP3w8r30Uu99Hn jx6hWgZBULT2N9A+vSG8foOVFQEwiXSF5YFlvuWJxvT0T5yJaBD4acJ+fi2+ivYP2Zaa Q1VA== X-Gm-Message-State: ALoCoQmTX6TZmjBhqZebzdr1d7LVVAFmxqdkIu6/xL/PGbkbqIdFarboj2HtXL8a+gTJr9o0msgT X-Received: by 10.14.37.4 with SMTP id x4mr23884757eea.16.1378664663822; Sun, 08 Sep 2013 11:24:23 -0700 (PDT) X-ProxyUser-IP: 86.6.30.159 Date: Sun, 8 Sep 2013 19:24:20 +0100 From: Peter Stephenson To: Zsh Hackers' List Subject: PATCH: execute-never style for MIME handler Message-ID: <20130908192420.2b52f0e5@pws-pc.ntlworld.com> X-Mailer: Claws Mail 3.8.0 (GTK+ 2.24.7; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit This helps with problems with trying to resolve between executable files and MIME types in the function-based MIME handler. If the file is executable it's usually useful to execute it, since that's what would happen if the MIME handler weren't installed. However, this isn't a good idea on a file system from an alien OS or a mounted external medium, and the problem is particularly acute for FATS-based file systems where everything looks executable. Now you can tell the handler about such file systems. I suppose you could even tell it to use wine with .exe files... diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 48c5105..9d3fc75 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -2881,6 +2881,28 @@ hence executable files are executed directly and not passed to a handler, and the option tt(AUTO_CD) may be used to change to directories that happen to have MIME suffixes. ) +kindex(execute-never, MIME style) +item(tt(execute-never))( +This style is useful in combination with tt(execute-as-is). It is +set to an array of patterns corresponding to full paths to files that +should never be treated as executable, even if the file passed to +the MIME handler matches tt(execute-as-is). This is useful for file +systems that don't handle execute permission or that contain executables +from another operating system. For example, if tt(/mnt/windows) is a +Windows mount, then + +example(zstyle ':mime:*' execute-never '/mnt/windows/*') + +will ensure that any files found in that area will be executed as MIME +types even if they are executable. As this example shows, the complete +file name is matched against the pattern, regardless of how the file +was passed to the handler. The file is resolved to a full path using +the tt(:A) modifier described in +ifzman(the subsection Modifers in zmanref(zshexpn))\ +ifnzman(noderef(Modifiers))); +this means that symbolic links are resolved where possible, so that +links into other file systems behave in the correct fashion. +) kindex(file-path, MIME style) item(tt(file-path))( Used if the style tt(find-file-in-path) is true for the same context. diff --git a/Functions/MIME/zsh-mime-handler b/Functions/MIME/zsh-mime-handler index 7245c20..b9f76c6 100644 --- a/Functions/MIME/zsh-mime-handler +++ b/Functions/MIME/zsh-mime-handler @@ -76,13 +76,14 @@ suffix=${suffix#*.} local handler flags no_sh no_bg arg bg_flag="&" integer i -local -a exec_asis hand_nonex +local -a exec_asis hand_nonex exec_never # 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. zsh-mime-contexts -a $suffix execute-as-is exec_asis || exec_asis=('*(*)' '*(/)') +zsh-mime-contexts -a $suffix execute-never exec_never # Set to a list of patterns for which the handler will be used even # if the file doesn't exist on the disk. @@ -125,6 +126,9 @@ fi for pattern in $exec_asis; do files=(${dirpref}${~pattern}) if [[ -n ${files[(r)$1]} ]]; then + for pattern in $exec_never; do + [[ ${1:A} = ${~pattern} ]] && break 2 + done if (( list )); then for (( i = 1; i <= $#; i++ )); do (( i == 1 )) || print -n " " -- Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/