Skip to content

Commit

Permalink
perf: batch tmux show (#288)
Browse files Browse the repository at this point in the history
* feat: batch tmux show options

* dont check for duplicates

* fix: status modules

* batch and cache build_window_icon

* perf: batch new options

* chore: tmux_batch_setup_module -> tmux_batch_setup_status_module

* fixup! perf: batch tmux show-options (#240)

Changes the line separator used by tmux_batch from ':' to the ascii unit
separator

FIXES: #240

* fix: string escaping of `..._tmux_batch_...`

`tmux show -v <option>` returns/prints the escaped value while the value string
of `tmux show <option>` is not escaped.

FIXES: #281
  • Loading branch information
vdbe authored Aug 12, 2024
1 parent df23892 commit 99013fa
Show file tree
Hide file tree
Showing 21 changed files with 371 additions and 136 deletions.
77 changes: 51 additions & 26 deletions builder/window_builder.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/sh


show_window_status=

build_window_format() {
local number="$1"
local color="$2"
Expand Down Expand Up @@ -93,34 +96,56 @@ build_window_format() {
}

build_window_icon() {
local window_status_icon_enable custom_icon_window_last \
custom_icon_window_zoom custom_icon_window_mark custom_icon_window_mark \
custom_icon_window_silent custom_icon_window_activity custom_icon_window_bell

window_status_icon_enable=$(get_tmux_option "@catppuccin_window_status_icon_enable" "yes")
custom_icon_window_last=$(get_tmux_option "@catppuccin_icon_window_last" "󰖰")
custom_icon_window_current=$(get_tmux_option "@catppuccin_icon_window_current" "󰖯")
custom_icon_window_zoom=$(get_tmux_option "@catppuccin_icon_window_zoom" "󰁌")
custom_icon_window_mark=$(get_tmux_option "@catppuccin_icon_window_mark" "󰃀")
custom_icon_window_silent=$(get_tmux_option "@catppuccin_icon_window_silent" "󰂛")
custom_icon_window_activity=$(get_tmux_option "@catppuccin_icon_window_activity" "󱅫")
custom_icon_window_bell=$(get_tmux_option "@catppuccin_icon_window_bell" "󰂞")

if [ "$window_status_icon_enable" = "yes" ]; then
# #!~[*-]MZ
local show_window_status=""
show_window_status+="#{?window_activity_flag, ${custom_icon_window_activity},}"
show_window_status+="#{?window_bell_flag, ${custom_icon_window_bell},}"
show_window_status+="#{?window_silence_flag, ${custom_icon_window_silent},}"
show_window_status+="#{?window_active, ${custom_icon_window_current},}"
show_window_status+="#{?window_last_flag, ${custom_icon_window_last},}"
show_window_status+="#{?window_marked_flag, ${custom_icon_window_mark},}"
show_window_status+="#{?window_zoomed_flag, ${custom_icon_window_zoom},}"
# Only update `show_window_status` if it's not empty
# this module is ran twice once for current and once for default
# meaning 2 calls to build_window_icon wich will/should both return the same
# result.
if [ -z "$show_window_status" ]; then
local window_status_icon_enable custom_icon_window_last \
custom_icon_window_zoom custom_icon_window_mark custom_icon_window_mark \
custom_icon_window_silent custom_icon_window_activity custom_icon_window_bell

# shellcheck disable=SC2034
local tmux_batch_options_commands=()
# shellcheck disable=SC2034
local tmux_batch_options=()

add_tmux_batch_option "@catppuccin_window_status_icon_enable"
add_tmux_batch_option "@catppuccin_icon_window_last"
add_tmux_batch_option "@catppuccin_icon_window_current"
add_tmux_batch_option "@catppuccin_icon_window_zoom"
add_tmux_batch_option "@catppuccin_icon_window_mark"
add_tmux_batch_option "@catppuccin_icon_window_silent"
add_tmux_batch_option "@catppuccin_icon_window_activity"
add_tmux_batch_option "@catppuccin_icon_window_bell"

run_tmux_batch_commands

window_status_icon_enable=$(get_tmux_batch_option "@catppuccin_window_status_icon_enable" "yes")
custom_icon_window_last=$(get_tmux_batch_option "@catppuccin_icon_window_last" "󰖰")
custom_icon_window_current=$(get_tmux_batch_option "@catppuccin_icon_window_current" "󰖯")
custom_icon_window_zoom=$(get_tmux_batch_option "@catppuccin_icon_window_zoom" "󰁌")
custom_icon_window_mark=$(get_tmux_batch_option "@catppuccin_icon_window_mark" "󰃀")
custom_icon_window_silent=$(get_tmux_batch_option "@catppuccin_icon_window_silent" "󰂛")
custom_icon_window_activity=$(get_tmux_batch_option "@catppuccin_icon_window_activity" "󱅫")
custom_icon_window_bell=$(get_tmux_batch_option "@catppuccin_icon_window_bell" "󰂞")

if [ "$window_status_icon_enable" = "yes" ]; then
# #!~[*-]MZ
show_window_status=""
show_window_status+="#{?window_activity_flag, ${custom_icon_window_activity},}"
show_window_status+="#{?window_bell_flag, ${custom_icon_window_bell},}"
show_window_status+="#{?window_silence_flag, ${custom_icon_window_silent},}"
show_window_status+="#{?window_active, ${custom_icon_window_current},}"
show_window_status+="#{?window_last_flag, ${custom_icon_window_last},}"
show_window_status+="#{?window_marked_flag, ${custom_icon_window_mark},}"
show_window_status+="#{?window_zoomed_flag, ${custom_icon_window_zoom},}"

fi
fi

if [ "$window_status_icon_enable" = "no" ]; then
local show_window_status=" #F"
if [ "$window_status_icon_enable" = "no" ]; then
show_window_status=" #F"
fi
fi

echo "$show_window_status"
Expand Down
94 changes: 66 additions & 28 deletions catppuccin.tmux
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,19 @@ main() {
# Aggregate all commands in one array
local tmux_commands=()

# Aggregate all tmux option for tmux_batch_option
local tmux_batch_options_commands=()
local tmux_batch_options=()

# Batch options for loading the colorscheme and everyting before
add_tmux_batch_option "@catppuccin_custom_plugin_dir"
add_tmux_batch_option "@catppuccin_flavour"

run_tmux_batch_commands

# module directories
local custom_path modules_custom_path modules_status_path modules_window_path modules_pane_path
custom_path="$(get_tmux_option "@catppuccin_custom_plugin_dir" "${PLUGIN_DIR}/custom")"
custom_path="$(get_tmux_batch_option "@catppuccin_custom_plugin_dir" "${PLUGIN_DIR}/custom")"
modules_custom_path=$custom_path
modules_status_path=$PLUGIN_DIR/status
modules_window_path=$PLUGIN_DIR/window
Expand All @@ -34,7 +44,7 @@ main() {
local color_interpolation=()
local color_values=()
local temp
theme="$(get_tmux_option "@catppuccin_flavour" "mocha")"
theme="$(get_tmux_batch_option "@catppuccin_flavour" "mocha")"
# NOTE: Pulling in the selected theme by the theme that's being set as local
# variables.
# https://github.com/dylanaraps/pure-sh-bible#parsing-a-keyval-file
Expand All @@ -55,16 +65,44 @@ main() {
color_values+=("${temp}")
done <"${PLUGIN_DIR}/themes/catppuccin_${theme}.tmuxtheme"

# Batch options for `./catppuccin.tmux`
add_tmux_batch_option "@catppuccin_status_default"
add_tmux_batch_option "@catppuccin_status_justify"
add_tmux_batch_option "@catppuccin_status_background"
add_tmux_batch_option "@catppuccin_menu_style"
add_tmux_batch_option "@catppuccin_menu_selected_style"
add_tmux_batch_option "@catppuccin_menu_border_style"
add_tmux_batch_option "@catppuccin_pane_status_enabled"
add_tmux_batch_option "@catppuccin_pane_border_status"
add_tmux_batch_option "@catppuccin_pane_left_separator"
add_tmux_batch_option "@catppuccin_pane_middle_separator"
add_tmux_batch_option "@catppuccin_pane_right_separator"
add_tmux_batch_option "@catppuccin_pane_number_position"
add_tmux_batch_option "@catppuccin_window_separator"
add_tmux_batch_option "@catppuccin_window_left_separator"
add_tmux_batch_option "@catppuccin_window_right_separator"
add_tmux_batch_option "@catppuccin_window_middle_separator"
add_tmux_batch_option "@catppuccin_window_number_position"
add_tmux_batch_option "@catppuccin_window_status_enable"
add_tmux_batch_option "@catppuccin_status_left_separator"
add_tmux_batch_option "@catppuccin_status_right_separator"
add_tmux_batch_option "@catppuccin_status_connect_separator"
add_tmux_batch_option "@catppuccin_status_fill"
add_tmux_batch_option "@catppuccin_status_modules_left"
add_tmux_batch_option "@catppuccin_status_modules_right"

run_tmux_batch_commands

# status general
local status_default status_justify status_background message_background
status_default=$(get_tmux_option "@catppuccin_status_default" "on")
status_default=$(get_tmux_batch_option "@catppuccin_status_default" "on")
# shellcheck disable=SC2121
set status "$status_default"

status_justify=$(get_tmux_option "@catppuccin_status_justify" "left")
status_justify=$(get_tmux_batch_option "@catppuccin_status_justify" "left")
set status-justify "$status_justify"

status_background=$(get_tmux_option "@catppuccin_status_background" "theme")
status_background=$(get_tmux_batch_option "@catppuccin_status_background" "theme")
if [ "${status_background}" = "theme" ]; then
set status-bg "${thm_bg}"
message_background="${thm_gray}"
Expand All @@ -87,9 +125,9 @@ main() {

# menu
local menu_style menu_selected_style menu_border_style
menu_style=$(get_interpolated_tmux_option "@catppuccin_menu_style" "default")
menu_selected_style=$(get_interpolated_tmux_option "@catppuccin_menu_selected_style" "fg=${thm_gray},bg=${thm_yellow}")
menu_border_style=$(get_interpolated_tmux_option "@catppuccin_menu_border_style" "default")
menu_style=$(get_interpolated_tmux_batch_option "@catppuccin_menu_style" "default")
menu_selected_style=$(get_interpolated_tmux_batch_option "@catppuccin_menu_selected_style" "fg=${thm_gray},bg=${thm_yellow}")
menu_border_style=$(get_interpolated_tmux_batch_option "@catppuccin_menu_border_style" "default")
set menu-style "$menu_style"
set menu-selected-style "$menu_selected_style"
set menu-border-style "$menu_border_style"
Expand All @@ -98,19 +136,19 @@ main() {
local pane_border_status pane_border_style \
pane_active_border_style pane_left_separator pane_middle_separator \
pane_right_separator pane_number_position pane_format
pane_status_enable=$(get_tmux_option "@catppuccin_pane_status_enabled" "no") # yes
pane_border_status=$(get_tmux_option "@catppuccin_pane_border_status" "off") # bottom
pane_status_enable=$(get_tmux_batch_option "@catppuccin_pane_status_enabled" "no") # yes
pane_border_status=$(get_tmux_batch_option "@catppuccin_pane_border_status" "off") # bottom
pane_border_style=$(
get_interpolated_tmux_option "@catppuccin_pane_border_style" "fg=${thm_gray}"
get_interpolated_tmux_batch_option "@catppuccin_pane_border_style" "fg=${thm_gray}"
)
pane_active_border_style=$(
get_interpolated_tmux_option "@catppuccin_pane_active_border_style" \
get_interpolated_tmux_batch_option "@catppuccin_pane_active_border_style" \
"#{?pane_in_mode,fg=${thm_yellow},#{?pane_synchronized,fg=${thm_magenta},fg=${thm_orange}}}"
)
pane_left_separator=$(get_tmux_option "@catppuccin_pane_left_separator" "")
pane_middle_separator=$(get_tmux_option "@catppuccin_pane_middle_separator" "")
pane_right_separator=$(get_tmux_option "@catppuccin_pane_right_separator" "")
pane_number_position=$(get_tmux_option "@catppuccin_pane_number_position" "left") # right, left
pane_left_separator=$(get_tmux_batch_option "@catppuccin_pane_left_separator" "")
pane_middle_separator=$(get_tmux_batch_option "@catppuccin_pane_middle_separator" "")
pane_right_separator=$(get_tmux_batch_option "@catppuccin_pane_right_separator" "")
pane_number_position=$(get_tmux_batch_option "@catppuccin_pane_number_position" "left") # right, left
pane_format=$(load_modules "pane_default_format" "$modules_custom_path" "$modules_pane_path")

setw pane-border-status "$pane_border_status"
Expand All @@ -123,14 +161,14 @@ main() {
window_middle_separator window_number_position window_status_enable \
window_format window_current_format

window_status_separator=$(get_interpolated_tmux_option "@catppuccin_window_separator" "")
window_status_separator=$(get_interpolated_tmux_batch_option "@catppuccin_window_separator" "")
setw window-status-separator "$window_status_separator"

window_left_separator=$(get_tmux_option "@catppuccin_window_left_separator" "")
window_right_separator=$(get_tmux_option "@catppuccin_window_right_separator" "")
window_middle_separator=$(get_tmux_option "@catppuccin_window_middle_separator" "")
window_number_position=$(get_tmux_option "@catppuccin_window_number_position" "left") # right, left
window_status_enable=$(get_tmux_option "@catppuccin_window_status_enable" "no") # right, left
window_left_separator=$(get_tmux_batch_option "@catppuccin_window_left_separator" "")
window_right_separator=$(get_tmux_batch_option "@catppuccin_window_right_separator" "")
window_middle_separator=$(get_tmux_batch_option "@catppuccin_window_middle_separator" "")
window_number_position=$(get_tmux_batch_option "@catppuccin_window_number_position" "left") # right, left
window_status_enable=$(get_tmux_batch_option "@catppuccin_window_status_enable" "no") # right, left

window_format=$(load_modules "window_default_format" "$modules_custom_path" "$modules_window_path")
setw window-status-format "$(do_color_interpolation "$window_format")"
Expand All @@ -141,16 +179,16 @@ main() {
# status module
local status_left_separator status_right_separator status_connect_separator \
status_fill status_modules_left status_modules_right
status_left_separator=$(get_tmux_option "@catppuccin_status_left_separator" "")
status_right_separator=$(get_tmux_option "@catppuccin_status_right_separator" "")
status_connect_separator=$(get_tmux_option "@catppuccin_status_connect_separator" "yes")
status_fill=$(get_tmux_option "@catppuccin_status_fill" "icon")
status_left_separator=$(get_tmux_batch_option "@catppuccin_status_left_separator" "")
status_right_separator=$(get_tmux_batch_option "@catppuccin_status_right_separator" "")
status_connect_separator=$(get_tmux_batch_option "@catppuccin_status_connect_separator" "yes")
status_fill=$(get_tmux_batch_option "@catppuccin_status_fill" "icon")

status_modules_left=$(get_tmux_option "@catppuccin_status_modules_left" "")
status_modules_left=$(get_tmux_batch_option "@catppuccin_status_modules_left" "")
loaded_modules_left=$(load_modules "$status_modules_left" "$modules_custom_path" "$modules_status_path")
set status-left "$(do_color_interpolation "$loaded_modules_left")"

status_modules_right=$(get_tmux_option "@catppuccin_status_modules_right" "application session")
status_modules_right=$(get_tmux_batch_option "@catppuccin_status_modules_right" "application session")
loaded_modules_right=$(load_modules "$status_modules_right" "$modules_custom_path" "$modules_status_path")
set status-right "$(do_color_interpolation "$loaded_modules_right")"

Expand Down
19 changes: 15 additions & 4 deletions pane/pane_default_format.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
show_pane_default_format() {
local number color background text fill
# shellcheck disable=SC2034
local tmux_batch_options_commands=()
# shellcheck disable=SC2034
local tmux_batch_options=()

add_tmux_batch_option "@catppuccin_pane_color"
add_tmux_batch_option "@catppuccin_pane_background_color"
add_tmux_batch_option "@catppuccin_pane_default_text"
add_tmux_batch_option "@catppuccin_pane_default_fill"

run_tmux_batch_commands

number="#{pane_index}"
color="$(get_tmux_option "@catppuccin_pane_color" "$thm_green")"
background="$(get_tmux_option "@catppuccin_pane_background_color" "$thm_gray")"
text="$(get_tmux_option "@catppuccin_pane_default_text" "#{b:pane_current_path}")"
fill="$(get_tmux_option "@catppuccin_pane_default_fill" "number")" # number, all, none
color="$(get_tmux_batch_option "@catppuccin_pane_color" "$thm_green")"
background="$(get_tmux_batch_option "@catppuccin_pane_background_color" "$thm_gray")"
text="$(get_tmux_batch_option "@catppuccin_pane_default_text" "#{b:pane_current_path}")"
fill="$(get_tmux_batch_option "@catppuccin_pane_default_fill" "number")" # number, all, none

default_pane_format=$(build_pane_format "$number" "$color" "$background" "$text" "$fill")

Expand Down
9 changes: 6 additions & 3 deletions status/application.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
show_application() {
local index icon color text module

tmux_batch_setup_status_module "application"
run_tmux_batch_commands

index=$1
icon=$(get_tmux_option "@catppuccin_application_icon" "")
color=$(get_tmux_option "@catppuccin_application_color" "$thm_pink")
text=$(get_tmux_option "@catppuccin_application_text" "#{pane_current_command}")
icon=$(get_tmux_batch_option "@catppuccin_application_icon" "")
color=$(get_tmux_batch_option "@catppuccin_application_color" "$thm_pink")
text=$(get_tmux_batch_option "@catppuccin_application_text" "#{pane_current_command}")

module=$(build_status_module "$index" "$icon" "$color" "$text")

Expand Down
38 changes: 21 additions & 17 deletions status/battery.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
show_battery() {
local index icon color text module

index=$1
icon=$(get_tmux_option "@catppuccin_battery_icon" "#{battery_icon}")
color=$(get_tmux_option "@catppuccin_battery_color" "$thm_yellow")
text=$(get_tmux_option "@catppuccin_battery_text" "#{battery_percentage}")
tmux_batch_setup_status_module "battery"

tmux_batch_options_commands+=("set-option -gq @batt_icon_charge_tier8 󰁹 ;")
tmux_batch_options_commands+=("set-option -gq @batt_icon_charge_tier7 󰂁 ;")
tmux_batch_options_commands+=("set-option -gq @batt_icon_charge_tier6 󰁿 ;")
tmux_batch_options_commands+=("set-option -gq @batt_icon_charge_tier5 󰁾 ;")
tmux_batch_options_commands+=("set-option -gq @batt_icon_charge_tier4 󰁽 ;")
tmux_batch_options_commands+=("set-option -gq @batt_icon_charge_tier3 󰁼 ;")
tmux_batch_options_commands+=("set-option -gq @batt_icon_charge_tier2 󰁻 ;")
tmux_batch_options_commands+=("set-option -gq @batt_icon_charge_tier1 󰁺 ;")
tmux_batch_options_commands+=("set-option -gq @batt_icon_status_charged 󰚥 ;")
tmux_batch_options_commands+=("set-option -gq @batt_icon_status_charging 󰂄 ;")
tmux_batch_options_commands+=("set-option -gq @batt_icon_status_discharging 󰂃 ;")
tmux_batch_options_commands+=("set-option -gq @batt_icon_status_unknown 󰂑 ;")
tmux_batch_options_commands+=("set-option -gq @batt_icon_status_attached 󱈑 ;")

tmux set-option -g @batt_icon_charge_tier8 '󰁹'
tmux set-option -g @batt_icon_charge_tier7 '󰂁'
tmux set-option -g @batt_icon_charge_tier6 '󰁿'
tmux set-option -g @batt_icon_charge_tier5 '󰁾'
tmux set-option -g @batt_icon_charge_tier4 '󰁽'
tmux set-option -g @batt_icon_charge_tier3 '󰁼'
tmux set-option -g @batt_icon_charge_tier2 '󰁻'
tmux set-option -g @batt_icon_charge_tier1 '󰁺'
tmux set-option -g @batt_icon_status_charged '󰚥'
tmux set-option -g @batt_icon_status_charging '󰂄'
tmux set-option -g @batt_icon_status_discharging '󰂃'
tmux set-option -g @batt_icon_status_unknown '󰂑'
tmux set-option -g @batt_icon_status_attached "󱈑"
run_tmux_batch_commands

index=$1
icon=$(get_tmux_batch_option "@catppuccin_battery_icon" "#{battery_icon}")
color=$(get_tmux_batch_option "@catppuccin_battery_color" "$thm_yellow")
text=$(get_tmux_batch_option "@catppuccin_battery_text" "#{battery_percentage}")

module=$(build_status_module "$index" "$icon" "$color" "$text")

Expand Down
9 changes: 6 additions & 3 deletions status/clima.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
show_clima() {
local index icon color text module

tmux_batch_setup_status_module "clima"
run_tmux_batch_commands

index=$1
icon="$(get_tmux_option "@catppuccin_clima_icon" "")"
color="$(get_tmux_option "@catppuccin_clima_color" "$thm_yellow")"
text="$(get_tmux_option "@catppuccin_clima_text" "#{clima}")"
icon="$(get_tmux_batch_option "@catppuccin_clima_icon" "")"
color="$(get_tmux_batch_option "@catppuccin_clima_color" "$thm_yellow")"
text="$(get_tmux_batch_option "@catppuccin_clima_text" "#{clima}")"

module=$(build_status_module "$index" "$icon" "$color" "$text")

Expand Down
Loading

0 comments on commit 99013fa

Please sign in to comment.