You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Oh My Zsh has a lot of variables that are treated as boolean true/false values. This includes some that the user provides to control options for plugins and so on. But we don't have a standardized representation for them.
Most of these treat 'true' as true and anything else as false. (I think.) Some treat non-empty as true (like the single-bracket [ $foo ] test). I think a couple expect '1' for true. And the tests are done differently. Some do [[ "$x" == "true" ]], some [ "$x" ], some do bash-style [[ "x$FOO" != "x" ]]. This is not a big issue; but it seems wrong that 1 is considered false in many of the option settings, and reading through boolean tests takes a little more work than it has to, IMO.
How about we standardize this? Pick a set of values that are considered true, define a function that can test those and turn it in to a $? exit status, and use that for booleans everywhere (at least user-visible ones). Say, "the strings 'true', 't', 'yes', 'on', and '1' are all considered true, maybe case-insensitively, and all other values are considered false", and a function omz_true() which tests a value, returning true ($? = 0) for the true strings and $?=1 otherwise. (List based on zsh's zstyle boolean values.)
One shortcoming is that a function call like that couldn't be used inside a [[ ... ]] test. If you need to combine a boolean test with other tests, you need to pull the omz_true outside the brackets.
# broken
if [[ omz_true "$MY_OPTION" && -n "$PROJECT_ROOT" ]] ...
# works
if omz_true "$MY_OPTION" && [[ -n "$PROJECT_ROOT" ]] ...
This discussion was converted from issue #4124 on October 08, 2023 12:59.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Oh My Zsh has a lot of variables that are treated as boolean true/false values. This includes some that the user provides to control options for plugins and so on. But we don't have a standardized representation for them.
Most of these treat
'true'
as true and anything else as false. (I think.) Some treat non-empty as true (like the single-bracket[ $foo ]
test). I think a couple expect'1'
for true. And the tests are done differently. Some do[[ "$x" == "true" ]]
, some[ "$x" ]
, some do bash-style[[ "x$FOO" != "x" ]]
. This is not a big issue; but it seems wrong that1
is considered false in many of the option settings, and reading through boolean tests takes a little more work than it has to, IMO.How about we standardize this? Pick a set of values that are considered true, define a function that can test those and turn it in to a
$?
exit status, and use that for booleans everywhere (at least user-visible ones). Say, "the strings'true'
,'t'
,'yes'
,'on'
, and'1'
are all considered true, maybe case-insensitively, and all other values are considered false", and afunction omz_true()
which tests a value, returning true ($?
= 0) for the true strings and$?
=1 otherwise. (List based on zsh'szstyle
boolean values.)One shortcoming is that a function call like that couldn't be used inside a
[[ ... ]]
test. If you need to combine a boolean test with other tests, you need to pull theomz_true
outside the brackets.Thoughts?
Beta Was this translation helpful? Give feedback.
All reactions