feat: add customization of status-right & status-left sections
This commit is contained in:
parent
80945039ba
commit
aac51493cb
5 changed files with 184 additions and 17 deletions
|
@ -3,25 +3,79 @@
|
|||
SCRIPT_SRC="$(dirname "${BASH_SOURCE[${#BASH_SOURCE[@]} - 1]}")"
|
||||
readonly SCRIPT_SRC
|
||||
CURRENT_DIR=$(cd "${SCRIPT_SRC}" >/dev/null 2>&1 && pwd) readonly CURRENT_DIR
|
||||
readonly THEME_OPTION="@tmux-gruvbox"
|
||||
readonly DEFAULT_THEME="dark"
|
||||
readonly CURRENT_DIR
|
||||
|
||||
get_theme() {
|
||||
local option="$1"
|
||||
local default_value="$2"
|
||||
local option_value
|
||||
option_value=$(tmux show-option -gqv "$option")
|
||||
if [ -z "$option_value" ]; then
|
||||
echo "$default_value"
|
||||
else
|
||||
echo "$option_value"
|
||||
fi
|
||||
}
|
||||
# hold the array of all command to configure tmux theme
|
||||
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"
|
||||
|
||||
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"
|
||||
|
||||
# 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
|
||||
|
||||
main() {
|
||||
local theme
|
||||
theme=$(get_theme "$THEME_OPTION" "$DEFAULT_THEME")
|
||||
tmux source-file "$CURRENT_DIR/tmux-gruvbox-${theme}.conf"
|
||||
local _theme
|
||||
_theme=$(tmux_get_option "$TMUX_GRUVBOX" "$DEFAULT_THEME")
|
||||
|
||||
# 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
|
||||
|
||||
# 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")
|
||||
|
||||
theme_args=(
|
||||
"$_status_left"
|
||||
"$_status_right"
|
||||
"$_window_status_current_format"
|
||||
"$_window_status_format"
|
||||
)
|
||||
|
||||
case $_theme in
|
||||
light)
|
||||
set_light_theme "${theme_args[@]}"
|
||||
;;
|
||||
dark | *)
|
||||
set_dark_theme "${theme_args[@]}"
|
||||
;;
|
||||
esac
|
||||
|
||||
# execute commands with tmux as array of options
|
||||
tmux "${TMUX_CMDS[@]}"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
|
|
19
src/helper_methods.sh
Normal file
19
src/helper_methods.sh
Normal file
|
@ -0,0 +1,19 @@
|
|||
#!/bin/bash
|
||||
|
||||
# simply print passed array
|
||||
#
|
||||
# example
|
||||
#
|
||||
# myarray=()
|
||||
# print_array myarray
|
||||
#
|
||||
print_array() {
|
||||
local -n arr # -n available over bash 4.3
|
||||
arr=$1
|
||||
|
||||
echo ""
|
||||
echo "begin >>>"
|
||||
printf "%s\n" "${arr[@]}"
|
||||
echo "<<< end"
|
||||
echo ""
|
||||
}
|
58
src/theme_gruvbox_dark.sh
Normal file
58
src/theme_gruvbox_dark.sh
Normal file
|
@ -0,0 +1,58 @@
|
|||
#!/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
|
||||
|
||||
tmux_append_seto "status" "on"
|
||||
|
||||
# default statusbar color
|
||||
tmux_append_seto "status-style" "bg=${col_bg1},fg=${col_fg1}"
|
||||
|
||||
# default window title colors
|
||||
tmux_append_setwo "window-status-style" "bg=${col_yellow2},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
|
||||
tmux_append_setwo "window-status-current-style" "bg=default,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" "${_left_status_value}"
|
||||
tmux_append_seto "status-right" "${_right_status_value}"
|
||||
|
||||
tmux_append_setwo "window-status-current-format" "${_window_status_current_format}"
|
||||
tmux_append_setwo "window-status-format" "${_window_status_format}"
|
||||
}
|
36
src/tmux_utils.sh
Normal file
36
src/tmux_utils.sh
Normal file
|
@ -0,0 +1,36 @@
|
|||
#!/bin/bash
|
||||
|
||||
# get desired option from tmux or default
|
||||
tmux_get_option() {
|
||||
local _option _default_value
|
||||
_option="$1"
|
||||
_default_value="$2"
|
||||
|
||||
local _option_value
|
||||
_option_value=$(tmux show-option -gqv "$_option")
|
||||
if [ -z "$_option_value" ]; then
|
||||
echo "$_default_value"
|
||||
else
|
||||
echo "$_option_value"
|
||||
fi
|
||||
}
|
||||
|
||||
# append preconfigured tmux set-option to global array
|
||||
tmux_append_seto() {
|
||||
local _option _value _result
|
||||
_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
|
||||
tmux_append_setwo() {
|
||||
local _option _value _result
|
||||
_option="$1"
|
||||
_value="$2"
|
||||
TMUX_CMDS+=("set-window-option" "-gq" "${_option}" "${_value}" ";")
|
||||
# _retult=("set-window-option -gq" "${_option}" "${_value}" ";")
|
||||
# echo "${_retult[*]}"
|
||||
}
|
|
@ -42,7 +42,7 @@ set-option -g status-right-length "80"
|
|||
set-window-option -g window-status-separator ""
|
||||
|
||||
set-option -g status-left "#[bg=colour241,fg=colour248] #S #[bg=colour237,fg=colour241,nobold,noitalics,nounderscore]"
|
||||
set-option -g status-right "#[bg=colour237,fg=colour239 nobold, nounderscore, noitalics]#[bg=colour239,fg=colour246] %Y-%m-%d %H:%M #[bg=colour239,fg=colour248,nobold,noitalics,nounderscore]#[bg=colour248,fg=colour237] #h "
|
||||
set-option -g status-right "#[bg=colour237,fg=colour239 nobold, nounderscore, noitalics]#[bg=colour239,fg=colour246] %Y-%m-%d %H:%M #[bg=colour239,fg=colour248,nobold,noitalics,nounderscore]#[bg=colour248,fg=colour237] #h #{tmux_mode_indicator}"
|
||||
|
||||
set-window-option -g window-status-current-format "#[bg=colour214,fg=colour237,nobold,noitalics,nounderscore]#[bg=colour214,fg=colour239] #I #[bg=colour214,fg=colour239,bold] #W#{?window_zoomed_flag,*Z,} #[bg=colour237,fg=colour214,nobold,noitalics,nounderscore]"
|
||||
set-window-option -g window-status-format "#[bg=colour239,fg=colour237,noitalics]#[bg=colour239,fg=colour223] #I #[bg=colour239,fg=colour223] #W #[bg=colour237,fg=colour239,noitalics]"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue