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
- X-seq: zsh-workers 51813
- From: Stephane Chazelas <stephane@xxxxxxxxxxxx>
- To: Mikael Magnusson <mikachu@xxxxxxxxx>
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: [PATCHv2] is-at-least compares zsh's version if $2 is provided but empty
- Date: Thu, 1 Jun 2023 19:23:24 +0100
- Archived-at: <https://zsh.org/workers/51813>
- In-reply-to: <CAHYJk3Q7ckoifHQXkAXbyAfuO3GDNsXOF=uVRD+gMjLS6jTTXg@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- Mail-followup-to: Mikael Magnusson <mikachu@xxxxxxxxx>, Zsh hackers list <zsh-workers@xxxxxxx>
- References: <20230528113907.hvxjuu4wwmettr5p@chazelas.org> <CAHYJk3Q7ckoifHQXkAXbyAfuO3GDNsXOF=uVRD+gMjLS6jTTXg@mail.gmail.com>
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