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