Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] fix/simplify is-at-least
> 2026/04/14 7:54、Philippe Altherr <philippe.altherr@xxxxxxxxx>のメール:
>
> Removing the leading text in both arguments may be a good compromise to remain closer to the current version.
Well, actually I did so in my first draft, but reconsidered that
the simpler the better.
Do we really need this? (patch against my previous patch: workers/54335).
diff --git a/Functions/Misc/is-at-least b/Functions/Misc/is-at-least
index f81593920..a145720c5 100644
--- a/Functions/Misc/is-at-least
+++ b/Functions/Misc/is-at-least
@@ -8,7 +8,7 @@
# {minimum,current}_version is a string consisting of a few 'segments'
# joined by either '.' or '-'. For example:
# 1.2-test 3.1.2-zefram4
-# 4.4.5beta23 12.34-patch23a
+# 4.4.5beta23 12.34-patch23alpha
#
# A segment with no digits, such as 'test' above, is ignored.
# If number of segments in the two version strings differ, missing
@@ -16,10 +16,16 @@
# 5.9, 5.9.0, 5.9.0.0, 5.9-test
# are all considered to be the same version.
#
+# For compatibility with older version, if a segment is like 'zefram4'
+# the leading text 'zefram' is removed. This means '3.1.2-zefram4' is
+# the same version as '3.1.2-4' (or '3.1.2.4'). But if a segment is
+# like 'patch23alpha', i.e., if another text ('alpha') follows the
+# digits, then it is used as is.
+
emulate -L zsh
setopt extended_glob
-local IFS=".-" min_ver cur_ver n
+local IFS=".-" min_ver cur_ver n order
: ${2=$ZSH_VERSION}
@@ -31,11 +37,17 @@ local IFS=".-" min_ver cur_ver n
min_ver=(${=1})
cur_ver=(${=2})
-# remove segmets containing no digits
+# remove segments containing no digits
min_ver=( ${min_ver:#[^0-9]##} )
cur_ver=( ${cur_ver:#[^0-9]##} )
(( $#min_ver == 0 || $#cur_ver == 0 )) && return 1
+# Compatibility with older version:
+# If a segment is of the form 'text123', remove the leading 'text'.
+# Segments like 'text123moretext' are not modified.
+min_ver=( ${min_ver:/[^0-9]##(#b)([0-9]##)/$match[1]} )
+cur_ver=( ${cur_ver:/[^0-9]##(#b)([0-9]##)/$match[1]} )
+
# find the first segment that differs
for (( n = 1; n <= $#min_ver; ++n )) do
[[ ${min_ver[n]} != ${cur_ver[n]-0} ]] && break
Messages sorted by:
Reverse Date,
Date,
Thread,
Author