From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23314 invoked by alias); 29 May 2018 22:22:13 -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: List-Unsubscribe: X-Seq: 42881 Received: (qmail 17729 invoked by uid 1010); 29 May 2018 22:22:13 -0000 X-Qmail-Scanner-Diagnostics: from park01.gkg.net by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(205.235.26.22):SA:0(-1.4/5.0):. Processed in 0.448953 secs); 29 May 2018 22:22:13 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,SPF_PASS,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.1 X-Envelope-From: SRS0=ogym=IQ=yahoo.co.uk=okiddle@bounces.park01.gkg.net X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | X-Virus-Scanned: by amavisd-new at gkg.net Authentication-Results: amavisd4.gkg.net (amavisd-new); dkim=pass (2048-bit key) header.d=yahoo.co.uk X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1527632526; bh=vaQRhjj6V/fZxc3TL95g30GtWiDfOE781UF5BpP+lJI=; h=From:To:Subject:Date:From:Subject; b=BIkJB3DiFF1xmwMol+DfNMufZQaH3NlKMvE3/Ol6G1mV94ab12ix860xStkKwAUCA88aDpLdx+xuED6VnHlk05tq9+lLLvTFg3lbDR9+xJhIv2d/F6ZKSNjXaIIN7Io/zXDTkfTJqXsAopqtR3gzO3TP9B2l0mYzEQqKBHABhoqjR0t5fztWjbgTVXhia2Ldj8Zs35bKXfQwvg+5IN/FQkXNWo2W/Jugx1Iw6/g0mpMUS/KnRGHLWfj+zZsMhFP0cpC69ILSwFTfpHkkFTzlTdPYxSCh8V4bmVTAMgOYKFaArxNh2dytZKkOTcnwUVpKYU/J6LCtXp5/BC6JuQjwoQ== X-YMail-OSG: XwiRYE8VM1lmTvh06Ik_audHQ4pBm8w5ylC.eju_tMAMqbOMXfK7IqU0ejdYDck Ft6IU7ovjW.EwEl8JcgoO5ugx161hVZCYub_w9_STqGCvcijXMDYu47vT4IZ.rbZohQ8LLpswKKm aba8W_YHphxKcyh1QPnw.r.2Qw2T7U_RE2GbwAVXRceM10ZNMOqvRaNKQwaxeVBbm5WtijO1uuui HlQ1P8VKfPJz8uCzksHEO1TeeUdRp805NijLb5AMZyswF0hDYt2SFKF0bNqWSxOyx0Qb63GUU7Zq eSR9tA7sfehWgzwmksGFbcFGickltkgCxIEt0jgG0yOcGDBgS024rZAW8ChyAi15UZA10B7inIIR ix5UkdzsrqKznX4QQB7N54Ap.61AX_RueCfD1bOlO6nvngDtkVV8eHTzVnGW3hkG4OLrgdA3nu73 ug6AQeq7k2hCbdnqNxv2rOU21EuD1VmlWpcas94BNgZpqcXv7F5zfkzoPzsUkg__SUfJgcFEm98q H6p..qWzVdwVRFkpFMpXQYTYUkMc3yaZY4idIY3TjX_u8Ko6CtIpHKcHIyXKmkZs5R8pf0eV1_Yw 3l.TUFG8doexsyXzjONLTt5EHxghxNvafXNg992_tLHxLN8iENjuY.UXyKCuAfF6l_eKH_Aqvu4j 0HuCibZtL.j2Xe4zB From: Oliver Kiddle To: Zsh workers Subject: PATCH: update ghostscript completion MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <13864.1527632525.1@thecus> Date: Wed, 30 May 2018 00:22:05 +0200 Message-ID: <13865.1527632525@thecus> This updates _gs. Any objections if I rename it to _ghostscript which is more meaningful and more inline with our conventions? My intention had just been to update the options but it seems that you can invoke gs directly to query some matches using PostScript code. So I had fun playing with that, for example you can get a list of supported paper sizes with: 'statusdict /.pagetypenames get { = } forall'. I suspect that a lot more along these lines is possible so if someone out there is a dab hand with ghostscript/postscript it'd be good to expand this further. It'd be particularly useful to complete options specific to output drivers (pdfwrite, jpeg etc). The redirection in _call_program seems to prevent gs from working so this doesn't use _call_program. Oliver diff --git a/Completion/Unix/Command/_gs b/Completion/Unix/Command/_gs index 98ba14912..2c6f40a35 100644 --- a/Completion/Unix/Command/_gs +++ b/Completion/Unix/Command/_gs @@ -1,12 +1,18 @@ #compdef gs ghostscript -if compset -N --; then +local -a specs names device + +device=( ${${path[1,CURRENT-1]}[(R)-sDEVICE=*]} ) + +if compset -N '-[-+@]'; then if [[ CURRENT -eq 1 ]]; then _pspdf else _message -e arguments 'userdict ARGUMENTS' return 1 fi +elif compset -P '@'; then + _files else local curcontext="$curcontext" state line expl ret=1 typeset -A opt_args @@ -15,20 +21,28 @@ else '-q[quiet startup]' \ '-g-[set device size]:device size (x):' \ '-r-[set resolution]:resolution ( or x):' \ - '-I[add to library file search path]:directory:_dir_list' \ + '-I+[add to library file search path]:directory:_dir_list' \ \*-{d,D}'-[define name with definition]:def:->dname' \ \*-{s,S}'-[define name with value]:def:->sname' \ + '-u[undefine name, cancelling -d or -s]:name:->uname' \ + '-P[look first in the current directory for library files]' \ + '-c[specify postscript code]:*[-@]*:postscript (-f to end)' \ + '-o+[specify OutputFile and enable -dPATCH and -dNOPAUSE options]: :->outfile' \ + '(- *)-'{h,\?}'[display useful options and available devices]' \ + '!-f-:PostScript or PDF file:_pspdf' \ '*:PostScript or PDF file:_pspdf' && ret=0 + [[ $state = sname ]] && compset -P '(stdout|OutputFile)=' && state=outfile case "$state" in dname) if [[ "$PREFIX" = *\=* ]]; then _message -e definition-values 'systemdict definition value' else - _wanted names expl 'systemdict definition name' \ - compadd -M 'm:{a-z}={A-Z}' - \ - DISKFONTS NOCACHE NOBIND NODISPLAY NOPAUSE PLATFONTS SAFER \ - WRITESYSTEMDICT && ret=0 + names=( ${${(f)"$($words[1] -q -o /dev/null -DNODISPLAY -c 'systemdict { type /booleantype eq { = } if } forall')"}:#*[a-z]*} ) + _wanted boolean-definitions expl 'systemdict boolean definition' compadd -M 'm:{a-z}={A-Z}' -a names && ret=0 + names=( FirstPage LastPage + $($words[1] -q -o /dev/null $device -DNODISPLAY -c 'currentpagedevice { type /integertype eq { = } if } forall') ) + _wanted integer-definitions expl 'currentpagedevice integer definition' compadd -S = -M 'm:{a-z}={A-Z}' -a names && ret=0 fi ;; sname) @@ -36,21 +50,71 @@ else case "$IPREFIX" in *DEVICE\=) _wanted devices expl 'ghostscript device' \ - compadd - "${(@)${=${$(_call_program devices gs -h)##* devices:}%%Search path:*}:#}" && ret=0 - ;; - *OutputFile\=) - _description files expl 'output file' - _files "$expl[@]" && ret=0 + compadd - ${(0)"$($words[1] -q -o /dev/null -DNODISPLAY -c 'devicenames { dup length string cvs print (\0) print } forall')"} && ret=0 ;; + *PAPERSIZE=) + names=( $($words[1] -q -o /dev/null -DNODISPLAY -c 'statusdict /.pagetypenames get { = } forall ') ) + _description paper-sizes expl 'paper size' + compadd "$expl[@]" -a names && ret=0 + ;; + *PDFSETTINGS=) + _description settings expl 'configuration' + compadd "$expl[@]" /screen /ebook /printer /prepress /default && ret=0 + ;; + *AutoRotatePages=) + _description settings expl 'orientation selection' + compadd "$expl[@]" /None /All /PageByPage && ret=0 + ;; + *CompatibilityLevel=) + _description pdf-levels expl 'PDF compatibility level' + compadd "$expl[@]" 1.{2,3,4} && ret=0 + ;; + *FONT=) # e.g. SUBSTFONT + _wanted fonts expl 'font' compadd - \ + $($words[1] -q -o /dev/null -DNODISPLAY -c '(*) { = } 256 string /Font resourceforall') && ret=0 + ;; *) _message -e values 'systemdict value' return 1 + ;; esac else - _wanted names expl 'systemdict name' \ - compadd -S\= -M 'm:{a-z}={A-Z}' - DEVICE OutputFile && ret=0 + _wanted definition-names expl 'systemdict name' compadd -S\= -M 'm:{a-z}={A-Z}' - \ + DEVICE OutputFile PAPERSIZE PDFSETTINGS CompatibilityLevel stdout COLORSCREEN \ + DITHERPPI InterpolateControl TextAlphaBits GraphicsAlphaBits PageList SUBSTFONT \ + && ret=0 fi ;; + uname) + _message -e definition-names 'systemdict definition name' + ;; + outfile) + if compset -P "*%"; then + specs=( + {d,i}':signed decimal number or with leading " numeric value of following character' + 'o:unsigned octal number' + 'u:unsigned decimal number' + {x,X}':unsigned hexadecimal number, letters capitalized as x' + '%:a literal percent sign' + '#:alternate form' + '0:zero pad to length' + '-:left adjust result' + '+:always place sign before number' + '.:precision' + ) + if ! compset -P '[0-9#.+-]##'; then + specs+=( + 'stdout:redirect to standard output' + 'stderr:redirect to standard error' + 'pipe%:redirect to a pipe' + ) + fi + _describe -t print-format-specifiers 'print format specifier' specs -S '' && ret=0 + else + _description files expl 'output file' + _files "$expl[@]" && ret=0 + fi + ;; esac return ret