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

[PATCHv2] is-at-least compares zsh's version if $2 is provided but empty



2023-05-28 17:51:49 +0200, Mikael Magnusson:
[...]
> This requires more changes to be useful:
> % is-at-least 1.9 ''; echo $?
> 1
> % is-at-least 0.9 ''; echo $?
> 0
[...]

Well spotted. I can't say I completely follow the logic in the
function, but those corner cases are probably better
special-cased.

diff --git a/Functions/Misc/is-at-least b/Functions/Misc/is-at-least
index d4ff3552a..5985684be 100644
--- a/Functions/Misc/is-at-least
+++ b/Functions/Misc/is-at-least
@@ -24,8 +24,14 @@ emulate -L zsh
 
 local IFS=".-" min_cnt=0 ver_cnt=0 part min_ver version order
 
+: ${2=$ZSH_VERSION}
+
+# sort out the easy corner cases first
+[[ $1 = $2 ]] && return 0 # same version
+[[ -n $2 ]] || return 1   # no version
+
 min_ver=(${=1})
-version=(${=2:-$ZSH_VERSION} 0)
+version=(${=2} 0)
 
 while (( $min_cnt <= ${#min_ver} )); do
   while [[ "$part" != <-> ]]; do




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