dotfiles/zsh/func/bool
Eryn Wells f7e802d3f3 [zsh] bool() function
Converts its first argument to a bool return value (0 or 1) and echos
"yes" or "no".
2025-08-01 10:40:10 -07:00

31 lines
509 B
Bash

# 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 "$@"