Revert "perf: batch tmux show-options (#240)" (#283)

This reverts commit 3c6f6f282b.
This commit is contained in:
vdbe 2024-08-06 13:25:59 +00:00 committed by GitHub
parent a2dda02b43
commit e2a1043f42
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 134 additions and 369 deletions

View file

@ -18,9 +18,11 @@ get_tmux_option() {
if [ "$value" = "null" ]
then
echo ""
else
echo "$value"
fi
else
echo "$default"
@ -38,9 +40,11 @@ get_interpolated_tmux_option() {
if [ "$value" = "null" ]
then
echo ""
else
do_color_interpolation "$value"
fi
else
echo "$default"
fi
@ -57,95 +61,3 @@ setw() {
local value=$2
tmux_commands+=(set-window-option -gq "$option" "$value" ";")
}
get_tmux_batch_option() {
local option default value
option="$1"
default="$2"
for option_index in "${!tmux_batch_options[@]}"; do
IFS=":" read -r read_option read_value <<<"${tmux_batch_options[$option_index]}"
if [[ "$read_option" == "$option" ]]; then
echo "$read_value"
return
fi
done
echo "$default"
}
get_interpolated_tmux_batch_option() {
local option default value
option="$1"
default="$2"
for option_index in "${!tmux_batch_options[@]}"; do
IFS=":" read -r read_option read_value <<<"${tmux_batch_options[$option_index]}"
if [[ "$read_option" == "$option" ]]; then
do_color_interpolation "$read_value"
return
fi
done
echo "$default"
}
add_tmux_batch_option() {
local option
option="$1"
tmux_batch_options_commands+=("show-option -gq $option ;")
}
set_tmux_batch_option() {
local option value
option="$1"
value="$2"
# NOTE: don't check for duplicates just append
# for option_index in "${!tmux_batch_options[@]}"; do
# read -d ':' -r read_option <<<"${tmux_batch_options[$option_index]}"
# if [[ "$read_option" == "$option" ]]; then
# tmux_batch_options["$option_index"]="$option:$value"
# return
# fi
# done
tmux_batch_options+=("$option:$value")
}
run_tmux_batch_commands() {
local temp
# shellcheck disable=SC2048,SC2086
while IFS=' ' read -r option value; do
if [ -n "$value" ]; then
if [ "$value" = "null" ]; then
set_tmux_batch_option "$option" ""
else
temp="${value%\"}"
temp="${temp#\"}"
set_tmux_batch_option "$option" "$temp"
fi
fi
done < <(tmux ${tmux_batch_options_commands[*]})
tmux_batch_options_commands=()
}
tmux_batch_setup_status_module() {
local name="$1"
# Don't want to run commands set before since we can't update
# `tmux_batch_options` for it
# shellcheck disable=SC2034
tmux_batch_options_commands=()
# No need to check previous options
# shellcheck disable=SC2034
tmux_batch_options=()
add_tmux_batch_option "@catppuccin_${name}_icon"
add_tmux_batch_option "@catppuccin_${name}_color"
add_tmux_batch_option "@catppuccin_${name}_text"
}