feat(guards): category variable overrides master in __fish_config_op_enabled
This commit is contained in:
@@ -5,14 +5,15 @@
|
||||
# __fish_config_op_enabled <category_variable>
|
||||
#
|
||||
# DESCRIPTION
|
||||
# Guard predicate for opinionated components (AGENTS.md Task #3). The master
|
||||
# switch __fish_config_opinionated is always evaluated first via
|
||||
# __fish_variable_check: a falsy master value (0/false/no/off/n) disables
|
||||
# every category at once, regardless of the category variable's own value.
|
||||
# Otherwise the supplied category variable is evaluated the same way.
|
||||
# Unset or empty variables (status 2) and unrecognized values (status 3)
|
||||
# leave the component enabled — opinionated components are active by
|
||||
# default and these variables are pure opt-out knobs.
|
||||
# Guard predicate for opinionated components (AGENTS.md Task #3).
|
||||
# The category variable is evaluated first via __fish_variable_check:
|
||||
# an explicit truthy value (1/true/yes/on/y) enables the component
|
||||
# regardless of the master switch; an explicit falsy value
|
||||
# (0/false/no/off/n) disables it regardless of the master switch.
|
||||
# Only when the category variable is unset or unrecognized (status 2
|
||||
# or 3) does the master switch __fish_config_opinionated apply: a
|
||||
# falsy master disables every unset-category component at once.
|
||||
# Unset master with unset category → enabled (active by default).
|
||||
#
|
||||
# ARGUMENTS
|
||||
# category_variable Name (without $) of the category opt-out variable:
|
||||
@@ -23,23 +24,33 @@
|
||||
# __fish_config_op_greeting
|
||||
#
|
||||
# RETURNS
|
||||
# 0 Component enabled (variables truthy, unset, or unrecognized)
|
||||
# 1 Component disabled (master or category variable is falsy)
|
||||
# 0 Component enabled (category explicitly truthy; or category unset
|
||||
# and master truthy/unset/unrecognized)
|
||||
# 1 Component disabled (category explicitly falsy; or category unset
|
||||
# and master explicitly falsy)
|
||||
#
|
||||
# EXAMPLE
|
||||
# if __fish_config_op_enabled __fish_config_op_aliases
|
||||
# alias grep='grep --color=auto'
|
||||
# end
|
||||
function __fish_config_op_enabled --description 'Check whether an opinionated component category is enabled'
|
||||
# Master switch first: falsy disables all categories unconditionally.
|
||||
__fish_variable_check __fish_config_opinionated
|
||||
if test $status -eq 1
|
||||
# Category variable checked first: an explicit value takes precedence over
|
||||
# the master switch in both directions.
|
||||
__fish_variable_check $argv[1]
|
||||
set -l cat_status $status
|
||||
|
||||
# Explicitly truthy → enabled regardless of master.
|
||||
if test $cat_status -eq 0
|
||||
return 0
|
||||
end
|
||||
|
||||
# Explicitly falsy → disabled regardless of master.
|
||||
if test $cat_status -eq 1
|
||||
return 1
|
||||
end
|
||||
|
||||
# Category variable: only an explicit falsy value disables the category.
|
||||
# Truthy (0), unset/empty (2), and garbage (3) all keep it enabled.
|
||||
__fish_variable_check $argv[1]
|
||||
# Category unset (2) or garbage (3): fall through to master switch.
|
||||
__fish_variable_check __fish_config_opinionated
|
||||
if test $status -eq 1
|
||||
return 1
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user