Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH 3/5: _imagemagick: complete all files if image files didn't match



On Wed, Aug 12, 2015 at 5:05 AM, Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> ---
>  Completion/Unix/Command/_imagemagick | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/Completion/Unix/Command/_imagemagick b/Completion/Unix/Command/_imagemagick
> index 115cb01..c43086c 100644
> --- a/Completion/Unix/Command/_imagemagick
> +++ b/Completion/Unix/Command/_imagemagick
> @@ -14,7 +14,7 @@ typeset -A opt_args
>  formats=jpg:jpeg:jp2:j2k:jpc:jpx:jpf:tiff:miff:ras:bmp:cgm:dcx:ps:eps:fig:fits:fpx:gif:mpeg:pbm:pgm:ppm:pcd:pcl:pdf:pcx:png:rad:rgb:rgba:rle:sgi:html:shtml:tga:ttf:uil:xcf:xwd:xbm:xpm:yuv
>
>  if (( $# )); then
> -  _files "$@" -g "*.(#i)(${~formats//:/|})(-.)"
> +  _files "$@" -g "*.(#i)(${~formats//:/|})(-.)" || _files "$@"
>    return
>  fi

Now that I'm looking at this line for the 500th time, I realize that
the ~ in there makes absolutely no sense, and shouldn't really work.
However, it seems to be totally ignored and harmless. I tried changing
formats to an array, and using this instead,
_files "$@" -g "*.(#i)(${(j:|:)~formats})(-.)"

And it works the same, next I tried (actually I did the other way
around but this is easier to follow)
_files "$@" -g "*.(#i)(${(~j:|:)formats})(-.)"
but this fails because for some reason this ~ is not ignored and the
pattern is evaluated at this point, expands to nothing, because
NULL_GLOB is set in completion, and we don't pass anything as an
argument to -g (because the * is quoted. If there was a literal *.jpg
it would probably do something else).

Long story short, let's do this while we're messing around in this
file, so this semi-anti-pattern doesn't spread when people look at
this file for modeling other completions.

diff --git i/Completion/Unix/Command/_imagemagick
w/Completion/Unix/Command/_imagemagick
index 115cb01..3b0b877 100644
--- i/Completion/Unix/Command/_imagemagick
+++ w/Completion/Unix/Command/_imagemagick
@@ -11,10 +11,10 @@ typeset -A opt_args
 #
 # and certainly many other things...

-formats=jpg:jpeg:jp2:j2k:jpc:jpx:jpf:tiff:miff:ras:bmp:cgm:dcx:ps:eps:fig:fits:fpx:gif:mpeg:pbm:pgm:ppm:pcd:pcl:pdf:pcx:png:rad:rgb:rgba:rle:sgi:html:shtml:tga:ttf:uil:xcf:xwd:xbm:xpm:yuv
+formats=(jpg jpeg jp2 j2k jpc jpx jpf tiff miff ras bmp cgm dcx ps
eps fig fits fpx gif mpeg pbm pgm ppm pcd pcl pdf pcx png rad rgb rgba
rle sgi html shtml tga ttf uil xcf xwd xbm xpm yuv)

 if (( $# )); then
-  _files "$@" -g "*.(#i)(${~formats//:/|})(-.)"
+  _files "$@" -g "*.(#i)(${(j:|:)formats})(-.)"
   return
 fi

@@ -444,7 +444,7 @@ case "$service" in
       '*-filter:filter type for resizing:(Point Box Triangle Hermite
Hanning Hamming Blackman Gaussian Quadratic Cubic Catrom Mitchell
Lanczos Bessel Sinc)' \
       '*-flip[vertical mirror image]' \
       '*-flop[horizontal mirror image]' \
-      "*-format:output file format:(${formats//:/ })" \
+      "*-format:output file format:($formats)" \
       '*-font:annotation font:_x_font' \
       '*-frame:border dimensions (<width>x<height>+<out>+<in>)' \
       '*-fuzz:maximum distance for equal colors' \

-- 
Mikael Magnusson



Messages sorted by: Reverse Date, Date, Thread, Author