zsh-workers
 help / color / mirror / code / Atom feed
From: Haakon Riiser <haakon.riiser@fys.uio.no>
To: zsh-workers@sunsite.dk
Cc: Oliver Kiddle <okiddle@yahoo.co.uk>
Subject: Re: Updated _acroread completer
Date: Mon, 25 Apr 2005 10:41:57 +0200	[thread overview]
Message-ID: <20050425084156.GA483@fox> (raw)
In-Reply-To: <7344.1114415007@trentino.groupinfra.com>

[-- Attachment #1: Type: text/plain, Size: 1539 bytes --]

[Oliver Kiddle]

>> The output of acroread -version cannot be piped to stdout for
>> some reason, so the version number must be read from
>> ACROREAD-PREFIX/Reader/AcroVersion.  Since acroread might have
>> been started via a wrapper script, the only failsafe way of
>> determining ACROREAD-PREFIX is to look at the output of acroread
>> -help.
> 
> Unfortunately, this doesn't work on the system I tried it on, using
> Adobe's rpm. /usr/bin/acroread is a symbolic like to
> /usr/local/Adobe/Acrobat7.0/bin/acroread. Handling that involves using ls
> to get the symlink destination.
> 
> Is acroread always a script? The following works well (and very quickly)
> on any system I have access to:
>   grep '^ver=' =acroread
> 
> From a completion function, we can use $commands[$words[1]] instead
> of =acroread.

It doesn't work when acroread is a wrapper script, which it is
in my case.  (I used a wrapper instead of a symlink, because the
script needs to do some things before it starts acroread, such
as turning off core dumps (some versions of acroread 5.x used to
crash a _lot_).)  Even if I rename the script to something other
than 'acroread', I still couldn't use =acroread since the real
acroread executable isn't in my PATH. :-/

So I'll just have to resolve the symlink using readlink.  I assume
the most portable way to do this is perl, unless there is a way
to make zsh expand the link itself.  I have attached a version that
does this.  Should handle any level of symbolic links that point to
new symbolic links.

-- 
 Haakon

[-- Attachment #2: _acroread --]
[-- Type: text/plain, Size: 3275 bytes --]

#compdef acroread

local curcontext="$curcontext" state line

# The output of acroread -version cannot be piped to stdout for some reason, so
# the version number must be read from ACROREAD-PREFIX/Reader/AcroVersion.
# Since acroread might have been started via a wrapper script, the only
# failsafe way of determining ACROREAD-PREFIX is to look at the output of
# acroread -help.
if [[ -z $_acroread_version ]]; then
    local acropath=${${(s. .)${${(f)"$($words[1] -help 2>&1)"}[1]}}[2]}
    while [[ -L $acropath ]]; do
        acropath=$(perl -e 'print readlink($ARGV[0])' $acropath)
    done
    local version_file=${acropath%/*}/../Reader/AcroVersion
    [[ -r $version_file ]] && _acroread_version=$(< $version_file)
fi

if [[ $_acroread_version == 7.* ]]; then
    _arguments -C \
      '--display=:X display:_x_display' \
      '--screen=:X screen (overrides the screen part of DISPLAY)' \
      --sync \
      '-geometry:[<width>x<height>][{+|-}<x offset>{+|-}<y offset>]' \
      -help \
      -iconic \
      '*-setenv:<var>=<value>' \
      -tempFile \
      '-tempFileTitle:title' \
      -openInNewWindow \
      -version \
      '-visual:X visual:_x_visual' \
      '-toPostScript:*::PostScript conversion options:= ->tops' \
      '*:PDF file:_files -g "*.(#i)pdf(-.)"' && return

    [[ -n "$state" ]] && _arguments \
      '-pairs:*:pdf_file_1 ps_file_1 ...:_files -g "*.(#i)(pdf|ps)(-.)"' \
      -binary \
      '-start:integer' \
      '-end:integer' \
      -optimizeForSpeed \
      -landscape \
      -reverse \
      '(-even)-odd' \
      '(-odd)-even' \
      -commentsOff \
      -annotsOff \
      '(-level3)-level2' \
      '(-level2)-level3' \
      -printerhalftones \
      -saveVM \
      '-scale:integer' \
      -shrink \
      -expand \
      '-size:page size (or custom size wxh in points):(letter tabloid ledger legal executive a3 a4 a5 b4 b5)' \
      '-transQuality:transparency flattening level:(1 2 3 4 5)' \
      '*:PDF file:_files -g "*.(#i)pdf(-.)"' && return
else
    _x_arguments -C \
      -help \
      -helpall \
      \*-iconic \
      \*+iconic \
      '-name:application name:_x_name' \
      '*-setenv:<var>=<value>' \
      -tempFile \
      '-tempFileTitle:title' \
      '(+useFrontEndProgram)-useFrontEndProgram' \
      '(-useFrontEndProgram)+useFrontEndProgram' \
      '-visual:X visual:_x_visual' \
      '-xrm:X resource specification:_x_resource' \
      '-toPostScript:*::PostScript conversion options:= ->tops' \
      '*:PDF file:_files -g "*.(#i)pdf(-.)"' && return

    [[ -n "$state" ]] && _arguments \
      '-pairs:*:pdf_file_1 ps_file_1 ...:_files -g "*.(#i)(pdf|ps)(-.)"' \
      -binary \
      '-start:integer' \
      '-end:integer' \
      -optimizeForSpeed \
      -landscape \
      -reverse \
      '(-even)-odd' \
      '(-odd)-even' \
      -commentsOff \
      '(-level2 -level3)-level1' \
      '(-level1 -level3)-level2' \
      '(-level1 -level2)-level3' \
      -printerhalftones \
      -saveVM \
      '-scale:integer' \
      -shrink \
      '-size:page size (or custom size wxh in points):(letter tabloid ledger legal executive a3 a4 a5 b4 b5)' \
      '-transQuality:transparency flattening level:(1 2 3 4 5)' \
      '*:PDF file:_files -g "*.(#i)pdf(-.)"' && return
fi

return 1

  reply	other threads:[~2005-04-25  8:42 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-14 13:47 Haakon Riiser
2005-04-15 11:11 ` Haakon Riiser
2005-04-25  7:43   ` Oliver Kiddle
2005-04-25  8:41     ` Haakon Riiser [this message]
2005-04-25  8:54       ` Oliver Kiddle
2005-04-25  8:58         ` Haakon Riiser
2005-04-25  9:39       ` Peter Stephenson
2005-04-25 13:00         ` Haakon Riiser
2005-04-25 13:36           ` Peter Stephenson

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=20050425084156.GA483@fox \
    --to=haakon.riiser@fys.uio.no \
    --cc=okiddle@yahoo.co.uk \
    --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).