zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@zsh.org
Subject: Re: possible 'is-at-least' bug?
Date: Fri, 11 Dec 2015 21:29:28 -0800	[thread overview]
Message-ID: <151211212928.ZM4290@torch.brasslantern.com> (raw)
In-Reply-To: <20151211112229.GB8386@zira.vinc17.org>

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
 


      reply	other threads:[~2015-12-12  5:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-04 23:45 TJ Luoma
2015-12-05  6:29 ` Benjamin R. Haskell
2015-12-07 10:25   ` Vincent Lefevre
2015-12-10  0:01     ` Bart Schaefer
2015-12-11 11:22       ` Vincent Lefevre
2015-12-12  5:29         ` Bart Schaefer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=151211212928.ZM4290@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).