From 2772b26704d4ecdf7d5ea19eecccc1c47a392856 Mon Sep 17 00:00:00 2001 From: rootiest Date: Tue, 23 Jun 2026 23:58:10 -0400 Subject: [PATCH] feat(config-settings): value-row set/get backend helpers --- functions/__config_settings_get_raw.fish | 27 ++++++++++ functions/__config_settings_set_value.fish | 63 ++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 functions/__config_settings_get_raw.fish create mode 100644 functions/__config_settings_set_value.fish diff --git a/functions/__config_settings_get_raw.fish b/functions/__config_settings_get_raw.fish new file mode 100644 index 0000000..4ecb93a --- /dev/null +++ b/functions/__config_settings_get_raw.fish @@ -0,0 +1,27 @@ +# Copyright (C) 2026 Rootiest +# SPDX-License-Identifier: AGPL-3.0-or-later + +# SYNOPSIS +# __config_settings_get_raw +# +# DESCRIPTION +# Prints the current value of a universal variable for display in the +# config-settings value pages. List variables are printed space-joined. +# Prints "DEFAULT" when the variable is unset in every scope. +# +# ARGUMENTS +# varname Variable name without the $ prefix +# +# RETURNS +# 0 Always; prints the value or "DEFAULT" to stdout +# +# EXAMPLE +# set v (__config_settings_get_raw sponge_delay) # "2" or "DEFAULT" +function __config_settings_get_raw + set -l varname $argv[1] + if set -q $varname + string join ' ' -- $$varname + else + echo DEFAULT + end +end diff --git a/functions/__config_settings_set_value.fish b/functions/__config_settings_set_value.fish new file mode 100644 index 0000000..88f83db --- /dev/null +++ b/functions/__config_settings_set_value.fish @@ -0,0 +1,63 @@ +# Copyright (C) 2026 Rootiest +# SPDX-License-Identifier: AGPL-3.0-or-later + +# SYNOPSIS +# __config_settings_set_value +# +# DESCRIPTION +# Sets a universal config variable from a config-settings value page, +# immediately and persistently. An empty erases the variable so the +# built-in default takes over. List types split on whitespace; all +# other types store it as a single value. When is a scrollback +# variable, the exported SCROLLBACK_HISTORY_* mirror is re-derived so the +# POSIX wrappers in the live session see the change without a re-login. +# +# ARGUMENTS +# varname Variable name without the $ prefix +# type "list" (whitespace-split) or any other tag (single value) +# value The new value; empty string erases (reset to default) +# +# RETURNS +# 0 Always +# +# EXAMPLE +# __config_settings_set_value sponge_delay int 5 +# __config_settings_set_value sponge_successful_exit_codes list "0 1 130" +# __config_settings_set_value __fish_scrollback_history_dir path ~/logs +# __config_settings_set_value __fish_user_dots_path path '' # reset +function __config_settings_set_value + set -l varname $argv[1] + set -l type $argv[2] + set -l value $argv[3] + + # stderr suppressed: editing a universal while a global of the same name + # shadows it makes interactive fish emit a shadow warning that would + # corrupt the in-place panel redraw (see __config_settings_apply). + if test -z "$value" + set -Ue $varname 2>/dev/null + else + switch $type + case list + set -U $varname (string split -n ' ' -- $value) 2>/dev/null + case '*' + # ponytail: values here are paths/ints/tokens, never leading-dash + set -U $varname $value 2>/dev/null + end + end + + # Scrollback export mirror — POSIX wrappers read these from the env. + switch $varname + case __fish_scrollback_history_dir + if set -q __fish_scrollback_history_dir + set -gx SCROLLBACK_HISTORY_DIR $__fish_scrollback_history_dir + else + set -gx SCROLLBACK_HISTORY_DIR "$HOME/.terminal_history" + end + case __fish_scrollback_history_max_files + if set -q __fish_scrollback_history_max_files + set -gx SCROLLBACK_HISTORY_MAX_FILES $__fish_scrollback_history_max_files + else + set -gx SCROLLBACK_HISTORY_MAX_FILES 100 + end + end +end