zsh-users
 help / color / mirror / code / Atom feed
73bf1ae1a37766482aad16797e51b9193659e200 blob 1667 bytes (raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
 
#
# 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!'
# is-at-least $ZSH_VERSION || print 'Something fishy here.'

emulate -L zsh

local IFS=".-" min_cnt=0 ver_cnt=0 part min_ver version order

min_ver=(${=1})
version=(${=2:-$ZSH_VERSION} 0)

while (( $min_cnt <= ${#min_ver} )); do
  while [[ "$part" != <-> ]]; do
    (( ++ver_cnt > ${#version} )) && return 0
    if [[ ${version[ver_cnt]} = *[0-9][^0-9]* ]]; then
      # A leading number and then some text.  Not a zsh version string,
      # so compare by sorting with numeric order.
      order=( ${version[ver_cnt]} ${min_ver[ver_cnt]} )
      [[ $order != ${${(On)order}} ]] && return 1
    fi
    part=${version[ver_cnt]##*[^0-9]}
  done

  while true; do
    (( ++min_cnt > ${#min_ver} )) && return 0
    [[ ${min_ver[min_cnt]} = <-> ]] && break
  done

  (( part > min_ver[min_cnt] )) && return 0
  (( part < min_ver[min_cnt] )) && return 1
  part=''
done
debug log:

solving d1073ff ...
found d1073ff in https://inbox.vuxu.org/zsh-users/151211212928.ZM4290@torch.brasslantern.com/
found d4b0e2f in https://git.vuxu.org/mirror/zsh/
preparing index
index prepared:
100644 d4b0e2fe024c3dffb23f92e8720d790637b6dfc7	Functions/Misc/is-at-least

applying [1/1] https://inbox.vuxu.org/zsh-users/151211212928.ZM4290@torch.brasslantern.com/
diff --git a/Functions/Misc/is-at-least b/Functions/Misc/is-at-least
index d4b0e2f..d1073ff 100644

Checking patch Functions/Misc/is-at-least...
Applied patch Functions/Misc/is-at-least cleanly.

index at:
100644 73bf1ae1a37766482aad16797e51b9193659e200	Functions/Misc/is-at-least

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).