9350e1ff8724341534a8def2ce76ede88a4c2868

Author
Marc Cornellà <hello@mcornella.com>
Committer
Marc Cornellà <hello@mcornella.com>
Date

Message

fix(coffee): fix completion bug on missing `coffee` command (#10759)

This commit fixes the error

  _coffee:49: bad math expression: operand expected at `< 2 '

when the coffee command is missing or the `coffee --version` command fails.

It also uses is-at-least to check for the cut-off version for suggesting
`--lint` and `--require` arguments, instead of using `cut` multiple times.

Fixes #10759

Diff

 1diff --git a/plugins/coffee/_coffee b/plugins/coffee/_coffee
 2index 5e52b30e6cd6e0e1899398a9c4424244bb8bb683..e2814f7ba712cb62f91e8d68345058114d0ce1e4 100644
 3--- a/plugins/coffee/_coffee
 4+++ b/plugins/coffee/_coffee
 5@@ -39,14 +39,14 @@
 6 #
 7 # ------------------------------------------------------------------------------
 8 
 9-local curcontext="$curcontext" state line ret=1 version opts first second third
10+local curcontext="$curcontext" state line ret=1 version
11+local -a opts
12 typeset -A opt_args
13-version=(${(f)"$(_call_program version $words[1] --version)"})
14+version=(${(f)"$(_call_program version $words[1] --version)"}) || return ret
15 version=${${(z)${version[1]}}[3]}
16-first=$(echo $version|cut -d '.' -f 1)
17-second=$(echo $version|cut -d '.' -f 2)
18-third=$(echo $version|cut -d '.' -f 3)
19-if (( $first < 2 )) &&  (( $second < 7 )) && (( $third < 3 ));then
20+
21+autoload -Uz is-at-least
22+if ! is-at-least 1.6.3 "$version"; then
23   opts+=('(-l --lint)'{-l,--lint}'[pipe the compiled JavaScript through JavaScript Lint]'
24          '(-r --require)'{-r,--require}'[require a library before executing your script]:library')
25 fi