zsh-workers
 help / color / mirror / code / Atom feed
From: "Johan Sundström" <johsu650@student.liu.se>
To: zsh-workers@sunsite.auc.dk
Subject: Contributed function: is-at-least
Date: Thu, 10 Feb 2000 13:29:21 +0100 (MET)	[thread overview]
Message-ID: <Pine.GSO.4.02.10002101317300.3097-100000@astmatix.ida.liu.se> (raw)

I've found this function very useful when moving among systems with zsh
versions of varying freshness, and thought it might do some good for
others too:

# $Id: is-at-least,v 1.4 2000/02/10 02:06:17 johan Exp $ -*- shell-script -*-
#
# Test whether $ZSH_VERSION (or some value of your choice, if a second argument
# is provided) is greater than or equal to x.y.z-r (in argument one). In fact,
# it'll accept any dot/dash-separated string of numbers as its second argument
# and compare it to the dot/dash-separated first argument. Leading non-number
# parts of a segment (such as the "zefram" in 3.1.2-zefram4) are not considered
# when the comparison is done; only the numbers matter. Any left-out segments
# in the first argument that are present in the version string compared are
# considered as zeroes, eg 3 == 3.0 == 3.0.0 == 3.0.0.0 and so on.
#
# Usage examples:
# is-at-least 3.1.6-15 && setopt NO_GLOBAL_RCS
# is-at-least 3.1.0 && setopt HIST_REDUCE_BLANKS
# is-at-least 586 $MACHTYPE && echo 'You could be running Mandrake!'

function is-at-least()
{
    emulate zsh ; setopt LOCAL_OPTIONS
    local IFS=".-" min_cnt=0 ver_cnt=0 part min_ver version
    min_ver=(${=1})
    version=(${=2:-$ZSH_VERSION} 0)
    while (( $min_cnt <= ${#min_ver} )) {
	while [[ "$part" != <-> ]] {
	    [[ $[++ver_cnt] > ${#version} ]] && return 0
	    part=${version[ver_cnt]##*[^0-9]}
	}
	[[ $[++min_cnt] > ${#min_ver} ]] && return 0
	(( part > min_ver[min_cnt] )) && return 0
	(( part < min_ver[min_cnt] )) && return 1
	part=''
    }
}


Some more usage examples, fetched from my ~/.zshrc:

if is-at-least 3.1.0 ; then
    setopt HIST_REDUCE_BLANKS	# on: Don't save extraneous between-word blanks in the history file

if is-at-least 3.1.2 ; then
  unsetopt KSH_AUTOLOAD		# off: Unfortunately, the zsh distribution forces me not to use this
				#      most excellent feature for now being. :-(
				# on: upon first execution of an autoloaded function, both perform
				#     its initialization code and the just defined function itself
    autoload ${^fpath}/*(.N:t)	# Autoload all functions (I wish I didn't have to)
if is-at-least 3.1.2-1 ; then
  unsetopt RM_STAR_WAIT		# off: I don't want to have to wait when removing files using globs
  unsetopt HIST_NO_FUNCTIONS	# off: I most certainly want function definitions in my history file
    setopt PROMPT_PERCENT	# on: % in prompts should expand the various prompt escapes
  unsetopt PROMPT_BANG		# off: %! is fine, thank you; I don't need an alias ! for that.
  unsetopt PRINT_EIGHT_BIT	# off: I have yet to encounter a system where my CTYPE isn't enough

if is-at-least 3.1.2-4 ; then
  unsetopt KSH_GLOB		# off: Use only zsh globbing; @*+?! get no special meaning before ()

if is-at-least 3.1.6 ; then
  unsetopt CHASE_DOTS		# off: don't resolve .. for the cd builtin looking at the filesystem
  unsetopt CHASE_LINKS		# off: don't resolve symlinks in $PWD when changing directory
#   setopt LOCAL_TRAPS		# does not make much sense outside of a function
# ZLS_COLOURS = ...

if is-at-least 3.1.6-6 ; then
    setopt LIST_PACKED		# on: shrink column widths in completion lists
  unsetopt LIST_ROWS_FIRST	# off: sort lists vertically in completion lists
fi # ZSH_VERSION >= 3.1.6-6
fi # ZSH_VERSION >= 3.1.6
fi # ZSH_VERSION >= 3.1.2-4
fi # ZSH_VERSION >= 3.1.2-1
fi # ZSH_VERSION >= 3.1.2
fi # ZSH_VERSION >= 3.1.0


                 reply	other threads:[~2000-02-10 12:29 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=Pine.GSO.4.02.10002101317300.3097-100000@astmatix.ida.liu.se \
    --to=johsu650@student.liu.se \
    --cc=zsh-workers@sunsite.auc.dk \
    /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).