Skip to content

Commit

Permalink
feat: batch tmux show options
Browse files Browse the repository at this point in the history
  • Loading branch information
vdbe committed Jul 14, 2024
1 parent 33c4fd6 commit 0865f1e
Show file tree
Hide file tree
Showing 19 changed files with 286 additions and 102 deletions.
104 changes: 78 additions & 26 deletions catppuccin.tmux
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/usr/bin/env bash3

# Set path of script
PLUGIN_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
Expand All @@ -21,9 +21,20 @@ 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 +45,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 +66,57 @@ 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_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"

# Module options that are _always_ required
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"

add_tmux_batch_option "@catppuccin_window_default_color"
add_tmux_batch_option "@catppuccin_window_default_background"
add_tmux_batch_option "@catppuccin_window_default_text"
add_tmux_batch_option "@catppuccin_window_default_fill"

add_tmux_batch_option "@catppuccin_window_current_color"
add_tmux_batch_option "@catppuccin_window_current_background"
add_tmux_batch_option "@catppuccin_window_current_text"
add_tmux_batch_option "@catppuccin_window_current_fill"

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 @@ -89,19 +141,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 @@ -114,14 +166,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 @@ -132,16 +184,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
8 changes: 4 additions & 4 deletions pane/pane_default_format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ show_pane_default_format() {
local number color background text fill

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_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_module "application"

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_module "application"
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
18 changes: 11 additions & 7 deletions status/cpu.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
show_cpu() {
local index icon color text module

index=$1
icon=$(get_tmux_option "@catppuccin_cpu_icon" "")
color="$(get_tmux_option "@catppuccin_cpu_color" "#{cpu_bg_color}")"
text="$(get_tmux_option "@catppuccin_cpu_text" "#{cpu_percentage}")"
tmux_batch_setup_module "application"

tmux_batch_options_commands+=("set-option -gq @cpu_low_bg_color $thm_yellow ;") # background color when cpu is low
tmux_batch_options_commands+=("set-option -gq @cpu_medium_bg_color $thm_orange ;") # background color when cpu is medium
tmux_batch_options_commands+=("set-option -gq @cpu_high_bg_color $thm_red ;") # background color when cpu is high

tmux set-option -g @cpu_low_bg_color "$thm_yellow" # background color when cpu is low
tmux set-option -g @cpu_medium_bg_color "$thm_orange" # background color when cpu is medium
tmux set-option -g @cpu_high_bg_color "$thm_red" # background color when cpu is high
run_tmux_batch_commands

index=$1
icon=$(get_tmux_batch_option "@catppuccin_cpu_icon" "")
color="$(get_tmux_batch_option "@catppuccin_cpu_color" "#{cpu_bg_color}")"
text="$(get_tmux_batch_option "@catppuccin_cpu_text" "#{cpu_percentage}")"

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

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

tmux_batch_setup_module "application"
run_tmux_batch_commands

index=$1
icon="$(get_tmux_option "@catppuccin_date_time_icon" "󰃰")"
color="$(get_tmux_option "@catppuccin_date_time_color" "$thm_blue")"
text="$(get_tmux_option "@catppuccin_date_time_text" "%Y-%m-%d %H:%M")"
icon="$(get_tmux_batch_option "@catppuccin_date_time_icon" "󰃰")"
color="$(get_tmux_batch_option "@catppuccin_date_time_color" "$thm_blue")"
text="$(get_tmux_batch_option "@catppuccin_date_time_text" "%Y-%m-%d %H:%M")"

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

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

tmux_batch_setup_module "application"
run_tmux_batch_commands

index=$1
icon=$(get_tmux_option "@catppuccin_directory_icon" "")
color=$(get_tmux_option "@catppuccin_directory_color" "$thm_pink")
text=$(get_tmux_option "@catppuccin_directory_text" "#{b:pane_current_path}")
icon=$(get_tmux_batch_option "@catppuccin_directory_icon" "")
color=$(get_tmux_batch_option "@catppuccin_directory_color" "$thm_pink")
text=$(get_tmux_batch_option "@catppuccin_directory_text" "#{b:pane_current_path}")

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

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

tmux_batch_setup_module "application"
run_tmux_batch_commands

index=$1
icon="$(get_tmux_option "@catppuccin_gitmux_icon" "󰊢")"
color="$(get_tmux_option "@catppuccin_gitmux_color" "$thm_green")"
text="$(get_tmux_option "@catppuccin_gitmux_text" "#(gitmux \"#{pane_current_path}\")")"
icon="$(get_tmux_batch_option "@catppuccin_gitmux_icon" "󰊢")"
color="$(get_tmux_batch_option "@catppuccin_gitmux_color" "$thm_green")"
text="$(get_tmux_batch_option "@catppuccin_gitmux_text" "#(gitmux \"#{pane_current_path}\")")"

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

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

tmux_batch_setup_module "application"
run_tmux_batch_commands

index=$1
icon=$(get_tmux_option "@catppuccin_host_icon" "󰒋")
color=$(get_tmux_option "@catppuccin_host_color" "$thm_magenta")
text=$(get_tmux_option "@catppuccin_host_text" "#H")
icon=$(get_tmux_batch_option "@catppuccin_host_icon" "󰒋")
color=$(get_tmux_batch_option "@catppuccin_host_color" "$thm_magenta")
text=$(get_tmux_batch_option "@catppuccin_host_text" "#H")

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

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

tmux_batch_setup_module "application"
run_tmux_batch_commands

index=$1
icon="$(get_tmux_option "@catppuccin_load_icon" "󰊚")"
color="$(get_tmux_option "@catppuccin_load_color" "$thm_blue")"
text="$(get_tmux_option "@catppuccin_load_text" "#{load_full}")"
icon="$(get_tmux_batch_option "@catppuccin_load_icon" "󰊚")"
color="$(get_tmux_batch_option "@catppuccin_load_color" "$thm_blue")"
text="$(get_tmux_batch_option "@catppuccin_load_text" "#{load_full}")"

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

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

tmux_batch_setup_module "application"
run_tmux_batch_commands

index=$1
icon="$( get_tmux_option "@catppuccin_<module_name>_icon" "" )"
color="$( get_tmux_option "@catppuccin_<module_name>_color" "$thm_orange" )"
text="$( get_tmux_option "@catppuccin_<module_name>_text" "#{pomodoro_status}" )"
icon="$( get_tmux_batch_option "@catppuccin_<module_name>_icon" "" )"
color="$( get_tmux_batch_option "@catppuccin_<module_name>_color" "$thm_orange" )"
text="$( get_tmux_batch_option "@catppuccin_<module_name>_text" "#{pomodoro_status}" )"

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

Expand Down
Loading

0 comments on commit 0865f1e

Please sign in to comment.