Add set --no-event

This allows running `set` without triggering any event handlers.

That is useful, for example, if you want to set a variable in an event
handler for that variable - we could do it, for example, in the
fish_user_path or fish_key_bindings handlers.

This is something the `block` builtin was supposed to be for, but it
never really worked because it only allows suppressing the event for
the duration, they would fire later. See #9030.

Because it is possible to abuse this, we only have a long-option so
that people see what is up.
This commit is contained in:
Fabian Boehm
2023-01-10 17:17:18 +01:00
parent 403920e9d6
commit f1e19884fb
4 changed files with 63 additions and 6 deletions

View File

@@ -965,4 +965,33 @@ set -e undefined[..1]
set -l negative_oob 1 2 3
set -q negative_oob[-10..1]
# --no-event
function onevent --on-variable nonevent
echo ONEVENT $argv $nonevent
end
set -g nonevent bar
set -e nonevent
# CHECK: ONEVENT VARIABLE SET nonevent bar
# CHECK: ONEVENT VARIABLE ERASE nonevent
set -g --no-event nonevent 2
set -e --no-event nonevent
set -S nonevent
set -g --no-event nonevent 3
set -e nonevent
# CHECK: ONEVENT VARIABLE ERASE nonevent
set -g nonevent 4
# CHECK: ONEVENT VARIABLE SET nonevent 4
set -e --no-event nonevent
set -l nonevent 4
set -e nonevent
# CHECK: ONEVENT VARIABLE SET nonevent
# CHECK: ONEVENT VARIABLE ERASE nonevent
exit 0