diff --git a/src/gruvbox-main.sh b/src/gruvbox-main.sh index 19218d8..9701c08 100755 --- a/src/gruvbox-main.sh +++ b/src/gruvbox-main.sh @@ -11,71 +11,71 @@ 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" +source "${CURRENT_DIR}/src/theme_gruvbox_dark256.sh" +source "${CURRENT_DIR}/src/theme_gruvbox_light256.sh" readonly TMUX_GRUVBOX="@tmux-gruvbox" -readonly TMUX_GRUVBOX_THEME="@tmux-gruvbox-theme" -readonly TMUX_GRUVBOX_LEFT_STATUS="@tmux-gruvbox-left-status" -readonly TMUX_GRUVBOX_RIGHT_STAUTS="@tmux-gruvbox-right-status" -readonly TMUX_GRUVBOX_WINDOW_STATUS_CURRENT_FORMAT="@tmux-gruvbox-window-status-current-format" -readonly TMUX_GRUVBOX_WINDOW_STATUS_FORMAT="@tmux-gruvbox-window-status-format" +readonly TMUX_GRUVBOX_STATUSBAR_ALPHA="@tmux-gruvbox-statusbar-alpha" +readonly TMUX_GRUVBOX_LEFT_STATUS_A="@tmux-gruvbox-left-status-a" +readonly TMUX_GRUVBOX_RIGHT_STAUTS_X="@tmux-gruvbox-right-status-x" +readonly TMUX_GRUVBOX_RIGHT_STAUTS_Y="@tmux-gruvbox-right-status-y" +readonly TMUX_GRUVBOX_RIGHT_STAUTS_Z="@tmux-gruvbox-right-status-z" -# 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 +# 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() { - local _theme - _theme=$(tmux_get_option "$TMUX_GRUVBOX" "$DEFAULT_THEME") + TMUX_CMDS=() # clear - # load proper palette for the theme soon to avoid additional variable interpolation - case $_theme in - light) - source "${CURRENT_DIR}/src/palette_gruvbox_light.sh" - ;; - dark | *) - source "${CURRENT_DIR}/src/palette_gruvbox_dark.sh" - ;; - esac + # load proper palette for the theme asap to avoid additional variable interpolation + local _theme + _theme=$(tmux_get_option "${TMUX_GRUVBOX}" "${DEFAULT_THEME}") + _statusbar_alpha=$(tmux_get_option "${TMUX_GRUVBOX_STATUSBAR_ALPHA}" "${DEFAULT_STATUSBAR_ALPHA}") - # 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]" + case "$_theme" in + light | light256) + source "${CURRENT_DIR}/src/palette_gruvbox_light.sh" + source "${CURRENT_DIR}/src/theme_gruvbox_light256.sh" + ;; + dark | dark256 | *) + source "${CURRENT_DIR}/src/palette_gruvbox_dark.sh" + source "${CURRENT_DIR}/src/theme_gruvbox_dark256.sh" + ;; + esac - _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") + 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" - ) + theme_args=( + "$_status_left_a" + "$_status_right_x" + "$_status_right_y" + "$_status_right_z" + "$_statusbar_alpha" + ) - case $_theme in - light) - set_light_theme "${theme_args[@]}" - ;; - dark | *) - set_dark_theme "${theme_args[@]}" - ;; - esac + case $_theme in + light | light256) + theme_set_light_256 "${theme_args[@]}" + ;; + dark | dark256 | *) + theme_set_dark_256 "${theme_args[@]}" + ;; + esac - # execute commands with tmux as array of options - tmux "${TMUX_CMDS[@]}" + # execute commands with tmux as array of options + tmux "${TMUX_CMDS[@]}" } main "$@" + +# vi: ft=bash diff --git a/src/theme_gruvbox_dark256.sh b/src/theme_gruvbox_dark256.sh new file mode 100644 index 0000000..0dcc014 --- /dev/null +++ b/src/theme_gruvbox_dark256.sh @@ -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]" +} diff --git a/src/theme_gruvbox_dark.sh b/src/theme_gruvbox_light256.sh similarity index 60% rename from src/theme_gruvbox_dark.sh rename to src/theme_gruvbox_light256.sh index 4ae4a3d..aaa5246 100644 --- a/src/theme_gruvbox_dark.sh +++ b/src/theme_gruvbox_light256.sh @@ -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" @@ -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]" } diff --git a/src/tmux_utils.sh b/src/tmux_utils.sh index 6e2ae12..cc235b3 100644 --- a/src/tmux_utils.sh +++ b/src/tmux_utils.sh @@ -1,17 +1,47 @@ #!/bin/bash # get desired option from tmux or default -tmux_get_option() { - local _option _default_value - _option="$1" +tmux_get_option_or_default() { + 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 - echo "$_default_value" + 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 "$_option_value" + echo "$_default_value" + fi +} + +# get desired tmux option or use given default value +tmux_get_option() { + 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 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 "$_default_value" fi } @@ -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 @@ -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" }