[zsh] bool() function
Converts its first argument to a bool return value (0 or 1) and echos "yes" or "no".
This commit is contained in:
parent
03fe14895c
commit
f7e802d3f3
1 changed files with 31 additions and 0 deletions
31
zsh/func/bool
Normal file
31
zsh/func/bool
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
# Eryn Wells <eryn@erynwells.me>
|
||||||
|
# vim: set ft=zsh:
|
||||||
|
|
||||||
|
function bool {
|
||||||
|
if [[ $1 -eq 0 ]]; then
|
||||||
|
echo "no"
|
||||||
|
return false
|
||||||
|
fi
|
||||||
|
|
||||||
|
local lowercase_value=${(L)1}
|
||||||
|
|
||||||
|
if [[ "$lowercase_value" == "yes" ]]; then
|
||||||
|
echo "yes"
|
||||||
|
return true
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$lowercase_value" == "no" ]]; then
|
||||||
|
echo "no"
|
||||||
|
return false
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$lowercase_value" =~ '^[0-9]+$' ]]; then
|
||||||
|
echo "yes"
|
||||||
|
return true
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "no"
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
bool "$@"
|
Loading…
Add table
Add a link
Reference in a new issue