summary refs log tree commit diff
path: root/Functions
diff options
context:
space:
mode:
authorBarton E. Schaefer <schaefer@zsh.org>2015-12-19 22:03:34 -0800
committerBarton E. Schaefer <schaefer@zsh.org>2015-12-19 22:03:34 -0800
commitaedff53d1f2436ebe59be3253ff4a22d442684d5 (patch)
tree8869fb092429d99e082794255f08888ad5c77a03 /Functions
parent7611e78ad1a8edbfcb486b19d4cfbc969ce1e771 (diff)
downloadzsh-aedff53d1f2436ebe59be3253ff4a22d442684d5.tar.gz
zsh-aedff53d1f2436ebe59be3253ff4a22d442684d5.tar.xz
zsh-aedff53d1f2436ebe59be3253ff4a22d442684d5.zip
users/21082 (expanded): a more complete sorting of version strings that are not in the form of zsh version numbers; additional explanatory comment
Diffstat (limited to 'Functions')
-rw-r--r--Functions/Misc/is-at-least20
1 files changed, 19 insertions, 1 deletions
diff --git a/Functions/Misc/is-at-least b/Functions/Misc/is-at-least
index d4b0e2fe0..d4ff3552a 100644
--- a/Functions/Misc/is-at-least
+++ b/Functions/Misc/is-at-least
@@ -13,10 +13,16 @@
 # 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.'
+#
+# Note that segments that contain no digits at all are ignored, and leading
+# text is discarded if trailing digits follow, because this was the meaning
+# of certain zsh version strings in the early 2000s.  Other segments that
+# begin with digits are compared using NUMERIC_GLOB_SORT semantics, and any
+# other segments starting with text are compared lexically.
 
 emulate -L zsh
 
-local IFS=".-" min_cnt=0 ver_cnt=0 part min_ver version
+local IFS=".-" min_cnt=0 ver_cnt=0 part min_ver version order
 
 min_ver=(${=1})
 version=(${=2:-$ZSH_VERSION} 0)
@@ -24,6 +30,18 @@ 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
+      # Contains a number followed by text.  Not a zsh version string.
+      order=( ${version[ver_cnt]} ${min_ver[ver_cnt]} )
+      if [[ ${version[ver_cnt]} = <->* ]]; then
+        # Leading digits, compare by sorting with numeric order.
+        [[ $order != ${${(On)order}} ]] && return 1
+      else
+        # No leading digits, compare by sorting in lexical order.
+        [[ $order != ${${(O)order}} ]] && return 1
+      fi
+      [[ $order[1] != $order[2] ]] && return 0
+    fi
     part=${version[ver_cnt]##*[^0-9]}
   done