about summary refs log tree commit diff
path: root/Functions/Misc/is-at-least
diff options
context:
space:
mode:
authorSven Wischnowsky <wischnow@users.sourceforge.net>2001-04-02 13:04:04 +0000
committerSven Wischnowsky <wischnow@users.sourceforge.net>2001-04-02 13:04:04 +0000
commit3d7263ff67534b5d533c1d78eca8d648b72bca93 (patch)
treed7c3f8d1fbaf58d52b092ef241dc37db974c370d /Functions/Misc/is-at-least
parentc6686513ef7eb29cbe4ed4cc27076d13b2e02ab5 (diff)
downloadzsh-3d7263ff67534b5d533c1d78eca8d648b72bca93.tar.gz
zsh-3d7263ff67534b5d533c1d78eca8d648b72bca93.tar.xz
zsh-3d7263ff67534b5d533c1d78eca8d648b72bca93.zip
after-move cleanup
Diffstat (limited to 'Functions/Misc/is-at-least')
-rw-r--r--Functions/Misc/is-at-least38
1 files changed, 38 insertions, 0 deletions
diff --git a/Functions/Misc/is-at-least b/Functions/Misc/is-at-least
new file mode 100644
index 000000000..6debe4c5a
--- /dev/null
+++ b/Functions/Misc/is-at-least
@@ -0,0 +1,38 @@
+#
+# 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 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} )); do
+  while [[ "$part" != <-> ]]; do
+    (( ++ver_cnt > ${#version} )) && return 0
+    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