Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: possible 'is-at-least' bug?



On Dec 11, 12:22pm, Vincent Lefevre wrote:
}
} > } On 2015-12-05 01:29:46 -0500, Benjamin R. Haskell wrote:
} > } > `is-at-least` isn't intended to be that general.
} > } > 
} > } > To do so would require a great deal more complexity.
} > 
} > To also split "1a1" and "1b2" etc. on the non-space between the numbers
} > and the letters, would require quite a bit more effort.
} 
} I meant that two such words could be compared without having to
} split them, thanks to numeric sorting.

Hmm.  Yes, that could be done.  I think it conflicts with sorting of zsh
version numbers, though, because "zefram2" is supposed to be considered
an older version substring than "pws4".  (Although no version of zsh has
had a ZSH_VERSION string that looks like that in more than a decade.)

Incidentally, is-at-least completely ignores segments that have no
digits in them at all, so zsh-5.2-dev-1 and zsh-5.2-test-1 will be
considered the same.

The following is what Vincent suggested but does not address dev / test.


diff --git a/Functions/Misc/is-at-least b/Functions/Misc/is-at-least
index d4b0e2f..d1073ff 100644
--- a/Functions/Misc/is-at-least
+++ b/Functions/Misc/is-at-least
@@ -16,7 +16,7 @@
 
 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 +24,12 @@ 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
 



Messages sorted by: Reverse Date, Date, Thread, Author