From f7e802d3f3bc22806a3b837da9ca85cffa26b2ca Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Tue, 3 Jun 2025 14:59:53 -0700 Subject: [PATCH] [zsh] bool() function Converts its first argument to a bool return value (0 or 1) and echos "yes" or "no". --- zsh/func/bool | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 zsh/func/bool diff --git a/zsh/func/bool b/zsh/func/bool new file mode 100644 index 0000000..c5bf961 --- /dev/null +++ b/zsh/func/bool @@ -0,0 +1,31 @@ +# Eryn Wells +# 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 "$@"