is.sh
Fancy alternative for old good test command.
Example
declare var=123
$ is equal "$var" 123.0 && printf 'it just works!\n'
it just works
$ is not a substring "$var" 'foobar' && printf "and it is easy to read\n"
and it is easy to read
Installation
In order to use is.sh you can install it with one of following 1-liners:
# Unix-like
$ sudo sh -c 'cd /usr/local/bin \
&& wget raw.githubusercontent.com/qzb/is.sh/latest/is.sh -O is \
&& chmod +x is'
# NPM
$ npm install -g is.sh
If you don't want to install is.sh system-wide you can just download it and source it from your script:
# retrieve and source
$ wget raw.githubusercontent.com/qzb/is.sh/latest/is.sh && . ./is.sh
Usage
is
without arguments will print out version followed by usageis --help
- displays usageis --version
- displays version
Conditions
checks if...
is equal "$valueA" "$valueB"
- 1st value is identical||equivalent to the 2nd- alternate(s)
eq
- alternate(s)
is matching "$regex" "$value"
- whole value matches the regular expression- alternate(s)
match
- alternate(s)
is substring "$valueA" "$valueB"
- 1st value is a part of the 2nd- alternate(s)
substr
- alternate(s)
is empty "$value"
- value is emptyis number "$value"
- value is a number- alternate(s)
num
- alternate(s)
is gt "$numberA" "$numberB"
- 1st number is greater than the 2ndis lt "$numberA" "$numberB"
- 1st number is less than the 2ndis ge "$numberA" "$numberB"
- 1st number is greater than or equal to the 2ndis le "$numberA" "$numberB"
- 1st number is less than or equal to the 2ndis file "$path"
- path is a fileis dir "$path"
- path is a directory- alternate(s)
directory
- alternate(s)
is link "$path"
- path is a symbolic link- alternate(s)
symlink
- alternate(s)
is existent "$path"
- there is anything at this path- alternate(s)
exists
,exist
,existing
- alternate(s)
is readable "$path"
- path is readableis writeable "$path"
- path is writeableis executable "$path"
- path is executableis available "$command"
- command is available (usingwhich
)- alternate(s)
installed
- alternate(s)
is cmd "$command"
- command is available (usingcommand
)- alternate(s)
command
- alternate(s)
is older "$pathA" "$pathB"
- 1st path is older than the 2ndis newer "$pathA" "$pathB"
- 1st path is newer than the 2ndis true "$value"
- value is equal totrue
or0
is false "$value"
- value is not equal totrue
and not equal to0
is truthy "$value"
- value is equal to0|t|y|true|yes|on
(case-insensitive)is falsey "$value"
- value is equal to1|f|n|false|no|off
(case-insensitive)is boolean NAME
- name is an variable, name is eithertruthy
orfalsey
- alternate(s)
bool
- alternate(s)
is alias NAME
- name is an aliasis builtin NAME
- name is a builtinis function NAME
- name is a function- alternate(s)
fn
- alternate(s)
is keyword NAME
- name is a keywordis array NAME
- name is a variableis hash NAME
- name is a variable- alternate(s)
dictionary
- alternate(s)
is integer NAME
- name is a variableis exported NAME
- name is a variable- alternate(s)
export
- alternate(s)
is set NAME
- name is a variable- alternate(s)
var
,variable
- alternate(s)
is in "$value" arrayName
- value is in the array
Negations
You can negate any condition by putting not in front of it.
$ is number '123' && printf 'number'
number
$ is not number 'abc' && printf 'not a number'
not a number
Articles
You can add a, an, and the articles before condition name.
$ is a number 5; printf '%s\n' $?
0
$ is not a substring abc defghi; printf '%s\n' $?
1
Examples
See the tests file for examples.
License
MIT