[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:
Eryn Wells 2025-06-03 14:59:53 -07:00
parent 03fe14895c
commit f7e802d3f3

31
zsh/func/bool Normal file
View 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 "$@"