1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-05-20 06:56:05 +02:00

42881: update options in ghostscript completion and query more matches directly from it

This commit is contained in:
Oliver Kiddle 2018-06-04 00:04:36 +02:00
parent 780c966972
commit 47f34eff93
3 changed files with 124 additions and 57 deletions

View File

@ -1,5 +1,8 @@
2018-06-03 Oliver Kiddle <okiddle@yahoo.co.uk>
* 42881: Completion/Unix/Command/_ghostscript: update options in
ghostscript completion and query more matches directly from it
* 42920: Completion/Linux/Command/_dkms: new dkms completion
2018-06-01 Peter Stephenson <p.stephenson@samsung.com>

View File

@ -0,0 +1,121 @@
#compdef gs ghostscript
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
_x_arguments -C \
'-q[quiet startup]' \
'-g-[set device size]:device size (<width>x<height>):' \
'-r-[set resolution]:resolution (<val> or <x>x<y>):' \
'-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
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)
if compset -P 1 '*='; then
case "$IPREFIX" in
*DEVICE\=)
_wanted devices expl 'ghostscript device' \
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 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
fi

View File

@ -1,57 +0,0 @@
#compdef gs ghostscript
if compset -N --; then
if [[ CURRENT -eq 1 ]]; then
_pspdf
else
_message -e arguments 'userdict ARGUMENTS'
return 1
fi
else
local curcontext="$curcontext" state line expl ret=1
typeset -A opt_args
_x_arguments -C \
'-q[quiet startup]' \
'-g-[set device size]:device size (<width>x<height>):' \
'-r-[set resolution]:resolution (<val> or <x>x<y>):' \
'-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' \
'*:PostScript or PDF file:_pspdf' && ret=0
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
fi
;;
sname)
if compset -P 1 '*='; then
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
;;
*)
_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
fi
;;
esac
return ret
fi