zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: Zsh hackers list <zsh-workers@sunsite.dk>
Subject: Re: two completion problems.
Date: Thu, 01 Mar 2007 15:22:11 +0000	[thread overview]
Message-ID: <200703011522.l21FMBR7002839@news01.csr.com> (raw)
In-Reply-To: <20070301141210.GA869@fermat.math.technion.ac.il>

"Zvi Har'El" wrote:
> I am using the latest CVS have two completion problems: 
> 1) acroread completion fails:
> 
> ~$ acroread <TAB>
> _acroread:12: no such file or directory: line

We search for the path to acrobat in order to check its version number
with the following substitution ($words[1] will be "acroread" or some
modification thereof):

  ${${(s. .)${${(f)"$($words[1] -help 2>&1)"}[1]}}[2]}

This only works if the path is the second word on the first non-empty
line.  I get '/usr/local/bin/acroread'.  Presumably this is different in
your version.

However, it's already been confused by that point by the substitution
    _acroread_version=${${${(Mf)"$(<$commands[$words[1]])"}:#ver=*}##ver=}
I think that (M) is in the wrong place and this should be:
    _acroread_version=${${(M)${(f)"$(<$commands[$words[1]])"}:#ver=*}##ver=}
I haven't checked when this got changed, but the previous version should
never have worked; parameter flags only apply (directly) to the current
level of substitution.

The following fixes that, and makes the test for whether we can
read the file on the second check safer.  (For me this test is
redundant since it refers to the same file we just checked, but
after fixing the version extraction it doesn't get that far.)

Index: Completion/X/Command/_acroread
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/X/Command/_acroread,v
retrieving revision 1.6
diff -u -r1.6 _acroread
--- Completion/X/Command/_acroread	26 Mar 2006 15:15:10 -0000	1.6
+++ Completion/X/Command/_acroread	1 Mar 2007 15:08:34 -0000
@@ -1,15 +1,25 @@
 #compdef acroread
 
 local curcontext="$curcontext" state line
+local cmdfile
 
-# Try extracting the version number directly from the executable.
-# (This will fail if the executable is a wrapper script for acroread.)
-local ver=${${${(Mf)"$(<$commands[$words[1]])"}:#ver=*}##ver=}
-[[ -n $ver ]] && _acroread_version=$ver
-
-if (( ! $+_acroread_version )); then
-  local acropath=${${(s. .)${${(f)"$($words[1] -help 2>&1)"}[1]}}[2]}
-  _acroread_version=${${${(Mf)"$(<$acropath)"}:#ver=*}##ver=}
+if [[ $words[1] = */* && -x $words[1] ]]; then
+  cmdfile=$words[1]
+elif [[ -x $commands[$words[1]] ]]; then
+  cmdfile=$commands[$words[1]]
+fi
+
+if [[ -z $_acroread_version ]]; then
+  # Try extracting the version number directly from the executable.
+  # (This will fail if the executable is a wrapper script for acroread.)
+  _acroread_version=${${(M)${(f)"$(<$cmdfile)"}:#ver=*}##ver=}
+
+  if [[ -z $_acroread_version ]]; then
+    local acropath=${${(s. .)${${(f)"$($words[1] -help 2>&1)"}[1]}}[2]}
+    if [[ -r $acropath ]]; then
+      _acroread_version=${${(M)${(f)"$(<$acropath)"}:#ver=*}##ver=}
+    fi
+  fi
 fi
 
 if [[ $_acroread_version == 7.* ]]; then

-- 
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

To get further information regarding CSR, please visit our Investor Relations page at http://ir.csr.com/csr/about/overview


  reply	other threads:[~2007-03-01 15:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-01 14:12 Zvi Har'El
2007-03-01 15:22 ` Peter Stephenson [this message]
2007-03-01 15:44   ` Zvi Har'El
2007-03-01 15:50     ` Peter Stephenson
2007-03-01 15:29 ` Zvi Har'El

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=200703011522.l21FMBR7002839@news01.csr.com \
    --to=pws@csr.com \
    --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).