Setup foo,bar,baz boolean vars
zstyle ':example:foo' doit yes
zstyle ':example:bar' doit no
# leave baz unset
zstyle -t
succeeds if the style is defined and is 'true', 'yes', 'on', or '1'
zstyle -T
succeeds if the style is undefined, or is 'true', 'yes', 'on', or '1'
foo
and bar
aren't very interesting because we explicitly set them.
# yes = success
zstyle -t ':example:foo' doit && echo "success" || echo "fail"
zstyle -T ':example:foo' doit && echo "success" || echo "fail"
# no = fail
zstyle -t ':example:bar' doit && echo "success" || echo "fail"
zstyle -T ':example:bar' doit && echo "success" || echo "fail"
# undefined = fail
zstyle -t ':example:baz' doit && echo "success" || echo "fail"
# undefined = success
zstyle -T ':example:baz' doit && echo "success" || echo "fail"
So the short version is...
If you want to default to 'no', and have to explicitly say 'yes', then test with zstyle -t
:
if zstyle -t ':example:foo' doit; then
echo "Make it so..."
fi
if zstyle -t ':example:bar' doit; then
echo "Never gonna happen"
fi
if zstyle -t ':example:baz' doit; then
echo "Never gonna happen"
fi
If you want to default to 'yes', and have to explicitly say 'no', then test with zstyle -T
:
if zstyle -T ':example:foo' doit; then
echo "Make it so..."
fi
if zstyle -T ':example:bar' doit; then
echo "Never gonna happen"
fi
if zstyle -T ':example:baz' doit; then
echo "Make it so..."
fi