Skip to content

Commit

Permalink
feat: rename to gruvbox_dark256 and implement alpha option
Browse files Browse the repository at this point in the history
  • Loading branch information
egel committed Sep 8, 2024
1 parent 50e66ae commit f25c798
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 67 deletions.
87 changes: 40 additions & 47 deletions gruvbox-tpm.tmux
Original file line number Diff line number Diff line change
Expand Up @@ -8,74 +8,67 @@ declate -a TMUX_CMDS
# load libraries
source "${CURRENT_DIR}/src/helper_methods.sh"
source "${CURRENT_DIR}/src/tmux_utils.sh"
source "${CURRENT_DIR}/src/theme_gruvbox_dark.sh"

TMUX_GRUVBOX="@tmux-gruvbox"
TMUX_GRUVBOX_THEME="@tmux-gruvbox-theme"
TMUX_GRUVBOX_LEFT_STATUS="@tmux-gruvbox-left-status"
TMUX_GRUVBOX_RIGHT_STAUTS="@tmux-gruvbox-right-status"
TMUX_GRUVBOX_WINDOW_STATUS_CURRENT_FORMAT="@tmux-gruvbox-window-status-current-format"
TMUX_GRUVBOX_WINDOW_STATUS_FORMAT="@tmux-gruvbox-window-status-format"

# define the reference names for further custom options
tmux_append_seto "${TMUX_GRUVBOX}"
tmux_append_seto "${TMUX_GRUVBOX_THEME}"
tmux_append_seto "${TMUX_GRUVBOX_LEFT_STATUS}"
tmux_append_seto "${TMUX_GRUVBOX_RIGHT_STAUTS}"
tmux_append_seto "${TMUX_GRUVBOX_WINDOW_STATUS_CURRENT_FORMAT}"
tmux_append_seto "${TMUX_GRUVBOX_WINDOW_STATUS_FORMAT}"

print_array TMUX_CMDS # print options
tmux "${TMUX_CMDS[@]}" # execute options
TMUX_CMDS=() # clean
TMUX_GRUVBOX_STATUSBAR_ALPHA="@tmux-gruvbox-statusbar-alpha"
TMUX_GRUVBOX_LEFT_STATUS_A="@tmux-gruvbox-left-status-a"
TMUX_GRUVBOX_RIGHT_STAUTS_X="@tmux-gruvbox-right-status-x"
TMUX_GRUVBOX_RIGHT_STAUTS_Y="@tmux-gruvbox-right-status-y"
TMUX_GRUVBOX_RIGHT_STAUTS_Z="@tmux-gruvbox-right-status-z"

# define simple theme options (no color interpolation required)
DEFAULT_THEME="dark"
DEFAULT_STATUSBAR_ALPHA=false
# defaults for theme option (with color interpolation)
DEFAULT_LEFT_STATUS_A='#S'
DEFAULT_RIGHT_STATUS_X='%Y-%m-%d'
DEFAULT_RIGHT_STATUS_Y='%H:%M'
DEFAULT_RIGHT_STATUS_Z='#h'

main() {
TMUX_CMDS=() # clear

# load proper palette for the theme asap to avoid additional variable interpolation
local _theme
_theme=$(tmux_get_option "$TMUX_GRUVBOX" "$DEFAULT_THEME")
_theme=$(tmux_get_option "${TMUX_GRUVBOX}" "${DEFAULT_THEME}")
_statusbar_alpha=$(tmux_get_option "${TMUX_GRUVBOX_STATUSBAR_ALPHA}" "${DEFAULT_STATUSBAR_ALPHA}")

# load proper palette for the theme soon to avoid additional variable interpolation
case $_theme in
light)
case "$_theme" in
light | light256)
source "${CURRENT_DIR}/src/palette_gruvbox_light.sh"
source "${CURRENT_DIR}/src/theme_gruvbox_light256.sh"
;;
dark | *)
dark | dark256 | *)
source "${CURRENT_DIR}/src/palette_gruvbox_dark.sh"
source "${CURRENT_DIR}/src/theme_gruvbox_dark256.sh"
;;
esac

# defaults for theme option
DEFAULT_THEME="dark"
DEFAULT_LEFT_STATUS="#[bg=${col_bg3},fg=${col_fg3}] #S #[bg=${col_bg1},fg=${col_bg3},nobold,noitalics,nounderscore]"
DEFAULT_RIGHT_STATUS="#[bg=${col_bg1},fg=${col_bg2},nobold,nounderscore,noitalics]#[bg=${col_bg2},fg=${col_fg4}] %Y-%m-%d  %H:%M #[bg=${col_bg2},fg=${col_fg3},nobold,noitalics,nounderscore]#[bg=${col_fg3},fg=${col_bg1}] #h #{tmux_mode_indicator}"
DEFAULT_WINDOW_STATUS_CURRENT_FORMAT="#[bg=${col_yellow2},fg=${col_bg1},nobold,noitalics,nounderscore]#[bg=${col_yellow2},fg=${col_bg2}] #I #[bg=${col_yellow2},fg=${col_bg2},bold] #W#{?window_zoomed_flag,*Z,} #[bg=${col_bg1},fg=${col_yellow2},nobold,noitalics,nounderscore]"
DEFAULT_WINDOW_STATUS_FORMAT="#[bg=${col_bg2},fg=${col_bg1},noitalics]#[bg=${col_bg2},fg=${col_fg1}] #I #[bg=${col_bg2},fg=${col_fg1}] #W #[bg=${col_bg1},fg=${col_bg2},noitalics]"

_status_left=$(tmux_get_option "$TMUX_GRUVBOX_LEFT_STATUS" "$DEFAULT_LEFT_STATUS")
_status_right=$(tmux_get_option "$TMUX_GRUVBOX_RIGHT_STAUTS" "$DEFAULT_RIGHT_STATUS")
_window_status_current_format=$(tmux_get_option "$TMUX_GRUVBOX_WINDOW_STATUS_CURRENT_FORMAT" "$DEFAULT_WINDOW_STATUS_CURRENT_FORMAT")
_window_status_format=$(tmux_get_option "$TMUX_GRUVBOX_WINDOW_STATUS_FORMAT" "$DEFAULT_WINDOW_STATUS_FORMAT")

echo "Theme: $_theme"
echo "Status left: $_status_left"
echo "Status right: $_status_right"
local _status_left _status_right _window_status_current_format _window_status_format
_status_left_a=$(tmux_get_option "$TMUX_GRUVBOX_LEFT_STATUS_A" "$DEFAULT_LEFT_STATUS_A")
_status_right_x=$(tmux_get_option "$TMUX_GRUVBOX_RIGHT_STAUTS_X" "$DEFAULT_RIGHT_STATUS_X")
_status_right_y=$(tmux_get_option "$TMUX_GRUVBOX_RIGHT_STAUTS_Y" "$DEFAULT_RIGHT_STATUS_Y")
_status_right_z=$(tmux_get_option "$TMUX_GRUVBOX_RIGHT_STAUTS_Z" "$DEFAULT_RIGHT_STATUS_Z")

theme_args=(
"$_status_left"
"$_status_right"
"$_window_status_current_format"
"$_window_status_format"
"$_status_left_a"
"$_status_right_x"
"$_status_right_y"
"$_status_right_z"
"$_statusbar_alpha"
)

case $_theme in
light)
set_light_theme "${theme_args[@]}"
light | light256)
theme_set_light_256 "${theme_args[@]}"
;;
dark | *)
set_dark_theme "${theme_args[@]}"
dark | dark256 | *)
theme_set_dark_256 "${theme_args[@]}"
;;
esac

print_array TMUX_CMDS
#print_array TMUX_CMDS
#tmux display-message ">${_status_right_z}<"

# execute commands with tmux as array of options
tmux "${TMUX_CMDS[@]}"
Expand Down
75 changes: 75 additions & 0 deletions src/theme_gruvbox_dark256.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash

# Themes may use different colors in sets therefore we setup dark and light
# separately.
#
# shellcheck disable=SC2154
theme_set_dark_256() {
local _left_status_a _right_status_x _right_status_y _right_status_z _statusbar_alpha
_left_status_a=$1
_right_status_x=$2
_right_status_y=$3
_right_status_z=$4
_statusbar_alpha=$5

tmux_append_seto "status" "on"

# default statusbar bg color
local _statusbar_bg="${col_bg1}"
if [[ "$_statusbar_alpha" == "true" ]]; then _statusbar_bg="default"; fi
tmux_append_seto "status-style" "bg=${_statusbar_bg},fg=${col_fg1}"

# default window title colors
local _window_title_bg=${col_yellow2}
if [[ "$_statusbar_alpha" == "true" ]]; then _window_title_bg="default"; fi
tmux_append_setwo "window-status-style" "bg=${_window_title_bg},fg=${col_bg1}"

# default window with an activity alert
tmux_append_setwo "window-status-activity-style" "bg=${col_bg1},fg=${col_fg3}"

# active window title colors
local active_window_title_bg=${col_yellow2}
if [[ "$_statusbar_alpha" == "true" ]]; then active_window_title_bg="default"; fi
tmux_append_setwo "window-status-current-style" "bg=${active_window_title_bg},fg=${col_bg1}" # TODO cosider removing red!

# pane border
tmux_append_seto "pane-active-border-style" "fg=${col_fg2}"
tmux_append_seto "pane-border-style" "fg=${col_bg1}"

# message infos
tmux_append_seto "message-style" "bg=${col_bg2},fg=${col_fg1}"

# writing commands inactive
tmux_append_seto "message-command-style" "bg=${col_fg3},fg=${col_bg1}"

# pane number display
tmux_append_seto "display-panes-active-colour" "${col_fg2}"
tmux_append_seto "display-panes-colour" "${col_bg1}"

# clock
tmux_append_setwo "clock-mode-colour" "${col_blue2}"

# bell
tmux_append_setwo "window-status-bell-style" "bg=${col_red2},fg=${col_bg}"

## Theme settings mixed with colors (unfortunately, but there is no cleaner way)
tmux_append_seto "status-justify" "left"
tmux_append_seto "status-left-style" none
tmux_append_seto "status-left-length" "80"
tmux_append_seto "status-right-style" none
tmux_append_seto "status-right-length" "80"
tmux_append_setwo "window-status-separator" ""

tmux_append_seto "status-left" "#[bg=${col_bg3},fg=${col_fg3}] ${_left_status_a} #[bg=${col_bg1},fg=${col_bg3},nobold,noitalics,nounderscore]"

# right status
local _status_right_bg=${col_bg1}
if [[ "$_statusbar_alpha" == "true" ]]; then _status_right_bg="default"; fi
tmux_append_seto "status-right" "#[bg=${_status_right_bg},fg=${col_bg2},nobold,nounderscore,noitalics]#[bg=${col_bg2},fg=${col_fg4}] ${_right_status_x}${_right_status_y} #[bg=${col_bg2},fg=${col_fg3},nobold,noitalics,nounderscore]#[bg=${col_fg3},fg=${col_bg1}] ${_right_status_z}"

# current window
tmux_append_setwo "window-status-current-format" "#[bg=${col_yellow2},fg=${col_bg1},nobold,noitalics,nounderscore]#[bg=${col_yellow2},fg=${col_bg2}] #I #[bg=${col_yellow2},fg=${col_bg2},bold] #W#{?window_zoomed_flag,*Z,} #{?window_end_flag,#[bg=default],#[bg=colour237]}#[fg=${col_yellow2},nobold,noitalics,nounderscore]"

# default window
tmux_append_setwo "window-status-format" "#[bg=${col_bg2},fg=${col_bg1},noitalics]#[bg=${col_bg2},fg=${col_fg1}] #I #[bg=${col_bg2},fg=${col_fg1}] #W #{?window_end_flag,#[bg=default],#[bg=colour237]}#[fg=${col_bg2},noitalics]"
}
20 changes: 10 additions & 10 deletions src/theme_gruvbox_dark.sh → src/theme_gruvbox_light256.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/bin/bash

# themes may use different colors in sets therefore we setup dark and light separately
set_dark_theme() {
local _left_status_value _right_status_value _window_status_current_format
_left_status_value=$1
_right_status_value=$2
_window_status_current_format=$3
_window_status_format=$4
theme_set_light_256() {
local _left_status_value _right_status_value _window_status_current_format _window_status_format
_left_status_a=$1
_right_status_x=$2
_right_status_y=$3
_right_status_z=$4

tmux_append_seto "status" "on"

Expand Down Expand Up @@ -50,9 +50,9 @@ set_dark_theme() {
tmux_append_seto "status-right-length" "80"
tmux_append_setwo "window-status-separator" ""

tmux_append_seto "status-left" "${_left_status_value}"
tmux_append_seto "status-right" "${_right_status_value}"
tmux_append_seto "status-left" "#[bg=${col_bg3},fg=${col_fg3}] ${_left_status_a} #[bg=${col_bg1},fg=${col_bg3},nobold,noitalics,nounderscore]"
tmux_append_seto "status-right" "#[bg=${col_bg1},fg=${col_bg2},nobold,nounderscore,noitalics]#[bg=${col_bg2},fg=${col_fg4}] ${_right_status_x}${_right_status_y} #[bg=${col_bg2},fg=${col_fg3},nobold,noitalics,nounderscore]#[bg=${col_fg3},fg=${col_bg1}] ${_right_status_z}"

tmux_append_setwo "window-status-current-format" "${_window_status_current_format}"
tmux_append_setwo "window-status-format" "${_window_status_format}"
tmux_append_setwo "window-status-current-format" "#[bg=${col_yellow2},fg=${col_bg1},nobold,noitalics,nounderscore]#[bg=${col_yellow2},fg=${col_bg2}] #I #[bg=${col_yellow2},fg=${col_bg2},bold] #W#{?window_zoomed_flag,*Z,} #[bg=${col_bg1},fg=${col_yellow2},nobold,noitalics,nounderscore]"
tmux_append_setwo "window-status-format" "#[bg=${col_bg2},fg=${col_bg1},noitalics]#[bg=${col_bg2},fg=${col_fg1}] #I #[bg=${col_bg2},fg=${col_fg1}] #W #[bg=${col_bg1},fg=${col_bg2},noitalics]"
}
62 changes: 52 additions & 10 deletions src/tmux_utils.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,47 @@
#!/bin/bash

# get desired option from tmux or default
tmux_get_option_or_default() {
local _option_name _default_value
_option_name="$1"
_default_value="$2"

local _current_option_value
_current_option_value=$(tmux show-option -gqv "$_option_name")
if [[ -n "$_current_option_value" ]]; then
echo "$_current_option_value"
else
echo "$_default_value"
fi
}

# get desired tmux option or use given default value
tmux_get_option() {
local _option _default_value
_option="$1"
local _option_name _default_value
_option_name="$1"
_default_value="$2"

local _option_value
_option_value=$(tmux show-option -gqv "$_option")
if [ -z "$_option_value" ]; then
local _current_option_value
_current_option_value=$(tmux show-option -gqv "$_option_name")
if [[ -n "$_current_option_value" ]]; then
echo "$_current_option_value"
else
echo "$_default_value"
fi
}

# get desired window-option from tmux or default
tmux_get_window_option() {
local _option_name _default_value
_option_name="$1"
_default_value="$2"

local _current_option_value
_current_option_value=$(tmux show-window-option -gqv "$_option_name")
if [[ -n "$_current_option_value" ]]; then
echo "$_current_option_value"
else
echo "$_option_value"
echo "$_default_value"
fi
}

Expand All @@ -21,8 +51,6 @@ tmux_append_seto() {
_option="$1"
_value="$2"
TMUX_CMDS+=("set-option" "-gq" "${_option}" "${_value}" ";")
# _retult=("set-option -gq" "${_option}" "${_value}" ";")
# echo "${_retult[*]}"
}

# append preconfigured tmux set-window-option to global array
Expand All @@ -31,6 +59,20 @@ tmux_append_setwo() {
_option="$1"
_value="$2"
TMUX_CMDS+=("set-window-option" "-gq" "${_option}" "${_value}" ";")
# _retult=("set-window-option -gq" "${_option}" "${_value}" ";")
# echo "${_retult[*]}"
}

# imediately execute tmux option
tmux_set_option_now() {
local _option_name _value
_option_name="$1"
_value="$2"
tmux set-option -gq "$_option_name" "$_value"
}

# imediately execute tmux option
tmux_set_window_option_now() {
local _option_name _value
_option_name="$1"
_value="$2"
tmux set-window-option -gq "$_option_name" "$_value"
}

0 comments on commit f25c798

Please sign in to comment.