1# 2# Test whether $ZSH_VERSION (or some value of your choice, if a second argument 3# is provided) is greater than or equal to x.y.z-r (in argument one). In fact, 4# it'll accept any dot/dash-separated string of numbers as its second argument 5# and compare it to the dot/dash-separated first argument. Leading non-number 6# parts of a segment (such as the "zefram" in 3.1.2-zefram4) are not considered 7# when the comparison is done; only the numbers matter. Any left-out segments 8# in the first argument that are present in the version string compared are 9# considered as zeroes, eg 3 == 3.0 == 3.0.0 == 3.0.0.0 and so on. 10# 11# Usage examples: 12# is-at-least 3.1.6-15 && setopt NO_GLOBAL_RCS 13# is-at-least 3.1.0 && setopt HIST_REDUCE_BLANKS 14# is-at-least 586 $MACHTYPE && echo 'You could be running Mandrake!' 15# is-at-least $ZSH_VERSION || print 'Something fishy here.' 16 17emulate -L zsh 18 19local IFS=".-" min_cnt=0 ver_cnt=0 part min_ver version 20 21min_ver=(${=1}) 22version=(${=2:-$ZSH_VERSION} 0) 23 24while (( $min_cnt <= ${#min_ver} )); do 25 while [[ "$part" != <-> ]]; do 26 (( ++ver_cnt > ${#version} )) && return 0 27 part=${version[ver_cnt]##*[^0-9]} 28 done 29 30 while true; do 31 (( ++min_cnt > ${#min_ver} )) && return 0 32 [[ ${min_ver[min_cnt]} = <-> ]] && break 33 done 34 35 (( part > min_ver[min_cnt] )) && return 0 36 (( part < min_ver[min_cnt] )) && return 1 37 part='' 38done 39