* Contributed function: is-at-least
@ 2000-02-10 12:29 Johan Sundström
0 siblings, 0 replies; only message in thread
From: Johan Sundström @ 2000-02-10 12:29 UTC (permalink / raw)
To: zsh-workers
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2000-02-10 12:29 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-02-10 12:29 Contributed function: is-at-least Johan Sundström
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).