Files
fish-config/functions/__config_toggle_apply.fish
T
rootiest 4210f3b445 fix: suppress fish shadow warning corrupting config-toggle redraw
When a category variable is set explicitly in both universal and session
scope, interactive fish prints a one-line stderr warning ("successfully set
universal 'X'; but a global by that name shadows it") on each `set -U`/`set
-g`. That stray line landed between the apply and the in-place panel redraw,
pushing the cursor down one row so the `\e[14A` cursor-up no longer reached
the top border — leaving it behind to stack on every toggle and persist
after exit.

Suppress stderr on the six set commands in __config_toggle_apply. The
warning is expected noise here since config-toggle edits both scopes
independently. The warning only fires in a real interactive TTY (not under
`fish -ic`), which is why it was easy to miss when testing.
2026-06-12 17:40:18 -04:00

63 lines
2.3 KiB
Fish

# Copyright (C) 2026 Rootiest
# SPDX-License-Identifier: AGPL-3.0-or-later
# SYNOPSIS
# __config_toggle_apply <varname> <scope> <value>
#
# DESCRIPTION
# Applies a state value to an opinionated-component variable in the given
# scope, immediately and persistently. Used by config-toggle's Left/Right
# (and vim h/l) directional handlers so the set/erase logic lives in one
# place. A value of "DEFAULT" erases the variable in that scope so the
# master switch / built-in default takes over again.
#
# universal → set -U (on/off) / set -Ue (DEFAULT)
# session → set -g (on/off) / set -eg (DEFAULT)
#
# ARGUMENTS
# varname Variable name without the $ prefix
# scope "universal" or "session"
# value "on", "off", or "DEFAULT"
#
# RETURNS
# 0 Always
#
# EXAMPLE
# __config_toggle_apply __fish_config_op_aliases universal off
# __config_toggle_apply __fish_config_op_greeting session DEFAULT
function __config_toggle_apply
set -l varname $argv[1]
set -l scope $argv[2]
set -l value $argv[3]
# stderr is suppressed because setting a value in one scope while the
# other scope already holds the same variable makes interactive fish
# emit a shadowing warning ("set: successfully set universal 'X'; but a
# global by that name shadows it"). config-toggle intentionally edits
# both scopes independently, so the warning is expected noise — and if
# it reached the terminal it would push the cursor down a row and
# corrupt the in-place panel redraw (leaving a stacked top border
# behind). Note: the warning only fires in a real interactive TTY, not
# under `fish -ic`, which is why it is easy to miss when testing.
switch $scope
case universal
switch $value
case on
set -U $varname on 2>/dev/null
case off
set -U $varname off 2>/dev/null
case DEFAULT
set -Ue $varname 2>/dev/null
end
case session
switch $value
case on
set -g $varname on 2>/dev/null
case off
set -g $varname off 2>/dev/null
case DEFAULT
set -eg $varname 2>/dev/null
end
end
end