feat(guards): per-category variable overrides master in __fish_config_op_enabled #41

Merged
rootiest merged 5 commits from feat/per-category-master-override into main 2026-06-11 03:09:52 +00:00
3 changed files with 36 additions and 17 deletions
+6 -1
View File
@@ -178,7 +178,7 @@ Everything opinionated in this config — command shadows, startup side-effects,
| `__fish_config_op_greeting` | Per-session `fish_greeting` (suppresses distro greetings such as CachyOS fastfetch by overriding with an empty function); first-run welcome banner |
| `__fish_config_opinionated` | Master switch — all six categories at once |
Set any of them to a falsy value (`0`, `false`, `no`, `off`, `n`) to disable; erase the variable to re-enable:
Set any of them to a falsy value (`0`, `false`, `no`, `off`, `n`) to disable; erase the variable to re-enable. An explicit per-category truthy value overrides a falsy master switch, so you can disable everything with `__fish_config_opinionated=0` and selectively re-enable individual categories:
```fish
# Plain shell: disable everything opinionated
@@ -187,8 +187,13 @@ set -U __fish_config_opinionated 0
# Or pick a single category, e.g. keep integrations but drop command shadows
set -U __fish_config_op_aliases off
# Minimal mode but keep the greeting (per-category overrides master)
set -U __fish_config_opinionated 0
set -U __fish_config_op_greeting 1
# Back to full flavor
set -Ue __fish_config_opinionated
set -Ue __fish_config_op_greeting
```
Command shadows react immediately; bindings, prompt, and abbreviations take effect in new shells. With aliases disabled, `rm` deletes permanently again instead of trashing. See `help config opinionated` for the full component list.
+9
View File
@@ -1387,6 +1387,10 @@ __fish_variable_check. Set a variable to any falsy value (0, false, no,
off, n) to disable its category; erase it or set a truthy value (1, true,
yes, on, y) to re-enable. Unset means enabled.
An explicit per-category truthy value takes precedence over the master
switch: setting __fish_config_opinionated=0 disables all unset categories,
but a category with an explicit truthy value remains enabled regardless.
Variable Disables
------------------------------ ------------------------------------
__fish_config_op_aliases Command shadows and flag injection:
@@ -1433,6 +1437,11 @@ Examples:
# Re-enable everything:
set -Ue __fish_config_opinionated
# Minimal mode but keep the greeting:
set -U __fish_config_opinionated 0
set -U __fish_config_op_greeting 1
# (erase both to go back to full-flavor defaults)
Notes:
- Command shadows (rm, cat, ls, ...) react immediately; conf.d-level
+21 -16
View File
@@ -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,27 @@
# __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 not falsy)
# 1 Component disabled (category explicitly falsy; or category unset and master falsy; or no argument with falsy master)
#
# 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
__fish_variable_check $argv[1]
set -l cat_status $status
if test $cat_status -eq 0
return 0
end
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]
# Status 3 (garbage) defers to master — an unrecognized value is not an opt-out.
__fish_variable_check __fish_config_opinionated
if test $status -eq 1
return 1
end