mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-10-27 04:40:59 +01:00
Initial revision
This commit is contained in:
parent
eaf9da50bc
commit
23cf2d0f7f
1 changed files with 33 additions and 0 deletions
33
Functions/Misc/is-at-least
Normal file
33
Functions/Misc/is-at-least
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
# $Id: is-at-least,v 1.1 2000/02/11 19:46:46 akr Exp $ -*- shell-script -*-
|
||||
#
|
||||
# Test whether $ZSH_VERSION (or some value of your choice, if a second argument
|
||||
# is provided) is greater than or equal to x.y.z-r (in argument one). In fact,
|
||||
# it'll accept any dot/dash-separated string of numbers as its second argument
|
||||
# and compare it to the dot/dash-separated first argument. Leading non-number
|
||||
# parts of a segment (such as the "zefram" in 3.1.2-zefram4) are not considered
|
||||
# when the comparison is done; only the numbers matter. Any left-out segments
|
||||
# in the first argument that are present in the version string compared are
|
||||
# considered as zeroes, eg 3 == 3.0 == 3.0.0 == 3.0.0.0 and so on.
|
||||
#
|
||||
# Usage examples:
|
||||
# is-at-least 3.1.6-15 && setopt NO_GLOBAL_RCS
|
||||
# is-at-least 3.1.0 && setopt HIST_REDUCE_BLANKS
|
||||
# is-at-least 586 $MACHTYPE && echo 'You could be running Mandrake!'
|
||||
|
||||
function is-at-least()
|
||||
{
|
||||
emulate zsh ; setopt LOCAL_OPTIONS
|
||||
local IFS=".-" min_cnt=0 ver_cnt=0 part min_ver version
|
||||
min_ver=(${=1})
|
||||
version=(${=2:-$ZSH_VERSION} 0)
|
||||
while (( $min_cnt <= ${#min_ver} )) {
|
||||
while [[ "$part" != <-> ]] {
|
||||
[[ $[++ver_cnt] > ${#version} ]] && return 0
|
||||
part=${version[ver_cnt]##*[^0-9]}
|
||||
}
|
||||
[[ $[++min_cnt] > ${#min_ver} ]] && return 0
|
||||
(( part > min_ver[min_cnt] )) && return 0
|
||||
(( part < min_ver[min_cnt] )) && return 1
|
||||
part=''
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue