feat(config): rewrite guard as self-identifying with C0 and site support

This commit is contained in:
2026-08-17 20:23:49 -04:00
parent 7fa5ca2568
commit 9642cd69db
+43 -38
View File
@@ -2,63 +2,68 @@
# SPDX-License-Identifier: AGPL-3.0-or-later # SPDX-License-Identifier: AGPL-3.0-or-later
# SYNOPSIS # SYNOPSIS
# __fish_config_op_enabled <category_variable> # __fish_config_op_enabled <identity> [<site>]
# #
# DESCRIPTION # DESCRIPTION
# Guard predicate for opinionated components (AGENTS.md Task #3). # Guard predicate for an opinionated component. <identity> is computed
# The category variable is evaluated first via __fish_variable_check: # by the caller, never hand-typed as a category name: (status
# an explicit truthy value (1/true/yes/on/y) enables the component # current-function) inside a function body, (status basename) at
# regardless of the master switch; an explicit falsy value # top-level conf.d/*.fish or config.fish code (fish has no API for a
# (0/false/no/off/n) disables it regardless of the master switch. # callee to introspect its own caller, so the caller must compute and
# Only when the category variable is unset or unrecognized (status 2 # pass its own identity -- see the spec's "A note on self-identifying").
# or 3) does the master switch __fish_config_opinionated apply: a # A trailing .fish is stripped so a status-basename identity and a
# falsy master disables every unset-category component at once. # status-current-function identity land in the same key space.
# Unset master with unset category → enabled (active by default).
# #
# One exception: __fish_config_op_logging (C5) is opt-in, because it # Looks up "<identity>:<site>" (site defaults to the empty/unnamed site)
# writes terminal output to disk. Unset or unrecognized means disabled, # in the generated component registry. No registry entry (unclassified,
# and the master switch cannot enable it — only an explicit truthy # or a doc header with no # COMPONENT section) resolves to enabled --
# value turns logging on. # the same fail-open default as an explicit `always/on` tag, so
# user-authored and third-party functions that never call this guard in
# the first place are unaffected, and one that somehow does is never
# silently broken by a missing header. A found `always/off` tag
# disables unconditionally; a found `always/on` tag enables
# unconditionally, short-circuiting before any other tagged
# sub-category is evaluated. Otherwise every tagged sub-category must
# pass the cascade (AND semantics).
# #
# ARGUMENTS # ARGUMENTS
# category_variable Name (without $) of the category opt-out variable: # identity (status current-function) or (status basename)
# __fish_config_op_aliases, __fish_config_op_autoexec, # site Optional site slug (see # COMPONENT header grammar);
# __fish_config_op_overrides, # omitted for the default/unnamed site
# __fish_config_op_integrations,
# __fish_config_op_logging, or
# __fish_config_op_greeting
# #
# EXIT STATUS # EXIT STATUS
# 0 Component enabled (category explicitly truthy; or category unset and master not falsy — except C5 logging, which requires an explicit truthy value) # 0 Component enabled
# 1 Component disabled (category explicitly falsy; or category unset and master falsy; or C5 logging unset; or no argument with falsy master) # 1 Component disabled
# #
# EXAMPLE # EXAMPLE
# if __fish_config_op_enabled __fish_config_op_aliases # if not __fish_config_op_enabled (status current-function)
# 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' # if not __fish_config_op_enabled (status current-function) exit-plain
__fish_variable_check $argv[1] # builtin exit
set -l cat_status $status # end
function __fish_config_op_enabled --description 'Guard for an opinionated component, identified by its own caller'
set -l identity (string replace -r '\.fish$' '' -- $argv[1])
set -l site $argv[2]
if test $cat_status -eq 0 set -l tags (__fish_config_op_registry_lookup $identity $site)
if test $status -ne 0
return 0 return 0
end end
if test $cat_status -eq 1 if contains -- always/off $tags
return 1 return 1
end end
if contains -- always/on $tags
# C5 logging is opt-in: it writes terminal output to disk, so an unset or return 0
# unrecognized value means off — the master switch cannot enable it.
if test "$argv[1]" = __fish_config_op_logging
return 1
end end
# Status 3 (garbage) defers to master — an unrecognized value is not an opt-out. for tag in $tags
__fish_variable_check __fish_config_opinionated set -l parts (string split -m 1 -- / $tag)
if test $status -eq 1 set -l category_var "__fish_config_op_$parts[1]"
return 1 set -l subcat_var "__fish_config_op_$parts[1]_$parts[2]"
__fish_config_op_cascade $category_var $subcat_var
or return 1
end end
return 0 return 0
end end