hardening IM7 usage vs. im6< with _pick_variant idiom and falling back to defaults absent match

Signed-off-by: Rob Jacques <2531474+robbyrob42@users.noreply.github.com>
This commit is contained in:
Rob Jacques 2026-03-23 11:48:20 -07:00
parent a06bb00f15
commit b1bf19c62d
No known key found for this signature in database
GPG Key ID: 166D8E7882750328
1 changed files with 19 additions and 1 deletions

View File

@ -38,7 +38,7 @@
# Authors # Authors
# ------- # -------
# #
# * Robert Jacques (https://github.com/robbyrob42) # * Robert Jacques (https://github.com/robertjacques)
# #
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@ -567,6 +567,24 @@ _magick_subcommands() {
_magick() { _magick() {
local curcontext="$curcontext" ret=1 local curcontext="$curcontext" ret=1
# Require ImageMagick 7+. Fall back to default file completion for IM6 or
# older so we don't offer IM7-specific options to the wrong version.
# For legacy binary names (convert, identify, etc.) we probe `magick` if
# available, otherwise the service command itself.
local _im_variant
local _im_pick_cmd
if (( $+commands[magick] )); then
_im_pick_cmd=magick
else
_im_pick_cmd=$service
fi
_pick_variant -c $_im_pick_cmd -r _im_variant \
im7='ImageMagick 7' im6='ImageMagick' unknown -version
if [[ $_im_variant != im7 ]]; then
_files
return
fi
case $service in case $service in
(convert) (convert)
_magick_convert && ret=0 _magick_convert && ret=0