tmux2k/scripts/tmux2k.sh

282 lines
12 KiB
Bash
Raw Normal View History

2022-08-09 06:28:34 +05:30
#!/usr/bin/env bash
2024-03-17 03:21:43 +05:30
2022-08-09 06:28:34 +05:30
export LC_ALL=en_US.UTF-8
current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$current_dir"/utils.sh
2024-03-16 23:36:18 +05:30
show_powerline=$(get_tmux_option "@tmux2k-show-powerline" true)
window_list_alignment=$(get_tmux_option "@tmux2k-window-list-alignment" 'centre')
2024-03-17 07:53:09 +05:30
refresh_rate=$(get_tmux_option "@tmux2k-refresh-rate" 60)
start_icon=$(get_tmux_option "@tmux2k-start-icon" '')
l_sep=$(get_tmux_option "@tmux2k-left-sep")
r_sep=$(get_tmux_option "@tmux2k-right-sep")
wl_sep=$(get_tmux_option "@tmux2k-window-left-sep")
wr_sep=$(get_tmux_option "@tmux2k-window-right-sep")
2024-03-17 02:41:14 +05:30
show_flags=$(get_tmux_option "@tmux2k-show-flags" true)
IFS=' ' read -r -a lplugins <<<"$(get_tmux_option '@tmux2k-left-plugins' 'git cpu ram')"
IFS=' ' read -r -a rplugins <<<"$(get_tmux_option '@tmux2k-right-plugins' 'battery network time')"
2024-03-27 10:26:05 +05:30
theme=$(get_tmux_option "@tmux2k-theme" 'default')
icons_only=$(get_tmux_option "@tmux2k-icons-only" false)
2024-04-02 11:09:50 +00:00
compact=$(get_tmux_option "@tmux2k-compact-windows" false)
2024-03-17 07:58:22 +05:30
text=$(get_tmux_option "@tmux2k-text" '#282a36')
2024-04-02 08:43:08 +05:30
bg_main=$(get_tmux_option "@tmux2k-bg-main" '#000000')
bg_alt=$(get_tmux_option "@tmux2k-bg-alt" '#1f1f1f')
2024-03-17 07:58:22 +05:30
black=$(get_tmux_option "@tmux2k-black" '#0a0a0f')
white=$(get_tmux_option "@tmux2k-white" '#d5d5da')
red=$(get_tmux_option "@tmux2k-red" '#ff001f')
light_red=$(get_tmux_option "@tmux2k-light-red" '#ff0055')
green=$(get_tmux_option "@tmux2k-green" '#3dd50a')
light_green=$(get_tmux_option "@tmux2k-light-green" '#ccffcc')
blue=$(get_tmux_option "@tmux2k-blue" '#1688f0')
light_blue=$(get_tmux_option "@tmux2k-light-blue" '#11dddd')
yellow=$(get_tmux_option "@tmux2k-yellow" '#ffb86c')
light_yellow=$(get_tmux_option "@tmux2k-light-yellow" '#ffd21a')
purple=$(get_tmux_option "@tmux2k-purple" '#bf58ff')
light_purple=$(get_tmux_option "@tmux2k-light-purple" '#ff65c6')
2024-03-26 15:40:35 +05:30
declare -A plugin_colors=(
["git"]="green text"
["cpu"]="blue text"
["cwd"]="purple text"
2024-03-26 15:40:35 +05:30
["ram"]="light_yellow text"
["gpu"]="yellow text"
["battery"]="light_purple text"
["network"]="purple text"
["bandwidth"]="purple text"
["ping"]="purple text"
["weather"]="yellow text"
["time"]="light_blue text"
["window"]="bg_main blue"
2024-03-26 15:40:35 +05:30
)
2024-03-16 23:39:02 +05:30
get_plugin_colors() {
local plugin_name="$1"
local default_colors="${plugin_colors[$plugin_name]}"
get_tmux_option "@tmux2k-${plugin_name}-colors" "$default_colors"
}
2024-03-16 23:36:18 +05:30
2024-03-17 07:53:09 +05:30
get_plugin_bg() {
IFS=' ' read -r -a colors <<<"$(get_plugin_colors "$1")"
return "${colors[0]}"
}
2024-03-27 10:26:05 +05:30
set_theme() {
case $theme in
"catppuccin")
bg_main=$(get_tmux_option "@tmux2k-bg-main" '#24273a')
bg_alt=$(get_tmux_option "@tmux2k-bg-alt" '#363a4f')
black=$(get_tmux_option "@tmux2k-black" '#1e2030')
white=$(get_tmux_option "@tmux2k-white" '#ffffff')
red=$(get_tmux_option "@tmux2k-red" '#ed8796')
light_red=$(get_tmux_option "@tmux2k-light-red" '#ee99a0')
green=$(get_tmux_option "@tmux2k-green" '#a6da95')
light_green=$(get_tmux_option "@tmux2k-light-green" '#8bd5ca')
blue=$(get_tmux_option "@tmux2k-blue" '#8aadf4')
light_blue=$(get_tmux_option "@tmux2k-light-blue" '#91d7e3')
yellow=$(get_tmux_option "@tmux2k-yellow" '#f5a97f')
light_yellow=$(get_tmux_option "@tmux2k-light-yellow" '#eed49f')
purple=$(get_tmux_option "@tmux2k-purple" '#b6a0fe')
2024-03-27 10:26:05 +05:30
light_purple=$(get_tmux_option "@tmux2k-light-purple" '#f5bde6')
;;
2024-04-02 08:43:42 +05:30
"duo")
duo_bg=$(get_tmux_option "@tmux2k-duo-bg" '#000000')
duo_fg=$(get_tmux_option "@tmux2k-duo-fg" '#ffffff')
text=$(get_tmux_option "@tmux2k-white" "$duo_bg")
bg_main=$(get_tmux_option "@tmux2k-bg-main" "$duo_bg")
bg_alt=$(get_tmux_option "@tmux2k-bg-alt" "$duo_bg")
black=$(get_tmux_option "@tmux2k-black" "$duo_bg")
white=$(get_tmux_option "@tmux2k-white" "$duo_fg")
red=$(get_tmux_option "@tmux2k-red" "$duo_fg")
light_red=$(get_tmux_option "@tmux2k-light-red" "$duo_fg")
green=$(get_tmux_option "@tmux2k-green" "$duo_fg")
light_green=$(get_tmux_option "@tmux2k-light-green" "$duo_fg")
blue=$(get_tmux_option "@tmux2k-blue" "$duo_fg")
light_blue=$(get_tmux_option "@tmux2k-light-blue" "$duo_fg")
yellow=$(get_tmux_option "@tmux2k-yellow" "$duo_fg")
light_yellow=$(get_tmux_option "@tmux2k-light-yellow" "$duo_fg")
purple=$(get_tmux_option "@tmux2k-purple" "$duo_fg")
light_purple=$(get_tmux_option "@tmux2k-light-purple" "$duo_fg")
;;
2024-03-27 11:06:30 +05:30
"gruvbox")
bg_main=$(get_tmux_option "@tmux2k-bg-main" '#282828')
bg_alt=$(get_tmux_option "@tmux2k-bg-alt" '#3c3836')
black=$(get_tmux_option "@tmux2k-black" '#282828')
white=$(get_tmux_option "@tmux2k-white" '#ebdbb2')
red=$(get_tmux_option "@tmux2k-red" '#cc241d')
light_red=$(get_tmux_option "@tmux2k-light-red" '#fb4934')
green=$(get_tmux_option "@tmux2k-green" '#98971a')
light_green=$(get_tmux_option "@tmux2k-light-green" '#b8bb26')
blue=$(get_tmux_option "@tmux2k-blue" '#458588')
light_blue=$(get_tmux_option "@tmux2k-light-blue" '#83a598')
yellow=$(get_tmux_option "@tmux2k-yellow" '#d79921')
light_yellow=$(get_tmux_option "@tmux2k-light-yellow" '#fabd2f')
purple=$(get_tmux_option "@tmux2k-purple" '#b162d6')
light_purple=$(get_tmux_option "@tmux2k-light-purple" '#f386cb')
2024-03-27 11:06:30 +05:30
;;
2024-04-02 08:43:21 +05:30
"monokai")
bg_main=$(get_tmux_option "@tmux2k-bg-main" '#272822')
bg_alt=$(get_tmux_option "@tmux2k-bg-alt" '#3e3d32')
black=$(get_tmux_option "@tmux2k-black" '#272822')
white=$(get_tmux_option "@tmux2k-white" '#f8f8f2')
red=$(get_tmux_option "@tmux2k-red" '#f92672')
light_red=$(get_tmux_option "@tmux2k-light-red" '#ff6188')
green=$(get_tmux_option "@tmux2k-green" '#a6e22e')
light_green=$(get_tmux_option "@tmux2k-light-green" '#a6e22e')
blue=$(get_tmux_option "@tmux2k-blue" '#66d9ef')
light_blue=$(get_tmux_option "@tmux2k-light-blue" '#66d9ef')
yellow=$(get_tmux_option "@tmux2k-yellow" '#e6db74')
light_yellow=$(get_tmux_option "@tmux2k-light-yellow" '#e6db74')
purple=$(get_tmux_option "@tmux2k-purple" '#ae81ff')
light_purple=$(get_tmux_option "@tmux2k-light-purple" '#fe81ff')
;;
2024-04-02 08:43:42 +05:30
"onedark")
bg_main=$(get_tmux_option "@tmux2k-bg-main" '#282c34')
bg_alt=$(get_tmux_option "@tmux2k-bg-alt" '#353b45')
black=$(get_tmux_option "@tmux2k-black" '#2d3139')
white=$(get_tmux_option "@tmux2k-white" '#abb2bf')
red=$(get_tmux_option "@tmux2k-red" '#e06c75')
light_red=$(get_tmux_option "@tmux2k-light-red" '#e06c75')
green=$(get_tmux_option "@tmux2k-green" '#98c379')
light_green=$(get_tmux_option "@tmux2k-light-green" '#98c379')
blue=$(get_tmux_option "@tmux2k-blue" '#61afef')
light_blue=$(get_tmux_option "@tmux2k-light-blue" '#61afef')
yellow=$(get_tmux_option "@tmux2k-yellow" '#e5c07b')
light_yellow=$(get_tmux_option "@tmux2k-light-yellow" '#e5c07b')
purple=$(get_tmux_option "@tmux2k-purple" '#c678fd')
light_purple=$(get_tmux_option "@tmux2k-light-purple" '#f678cd')
;;
2024-03-27 10:26:05 +05:30
esac
if $icons_only; then
show_powerline=false
2024-03-27 10:26:05 +05:30
text=$bg_main
plugin_colors=(
["git"]="text green"
["cpu"]="text blue"
2024-11-03 23:51:08 +05:30
["cwd"]="text light_green"
2024-03-27 10:26:05 +05:30
["ram"]="text light_yellow"
["gpu"]="text yellow"
["battery"]="text light_purple"
["network"]="text purple"
["bandwidth"]="text purple"
["ping"]="text purple"
["weather"]="text yellow"
["time"]="text light_blue"
["window"]="blue bg_main"
2024-03-27 10:26:05 +05:30
)
fi
}
2024-03-17 07:53:09 +05:30
set_options() {
tmux set-option -g status-interval "$refresh_rate"
tmux set-option -g status-left-length 100
tmux set-option -g status-right-length 100
tmux set-option -g status-left ""
tmux set-option -g status-right ""
tmux set-option -g pane-active-border-style "fg=${blue}"
tmux set-option -g pane-border-style "fg=${bg_main}"
tmux set-option -g message-style "bg=${bg_main},fg=${blue}"
tmux set-option -g status-style "bg=${bg_main},fg=${white}"
tmux set -g status-justify "$window_list_alignment"
2024-03-17 07:53:09 +05:30
tmux set-window-option -g window-status-activity-style "bold"
tmux set-window-option -g window-status-bell-style "bold"
tmux set-window-option -g window-status-current-style "bold"
}
start_icon() {
case $start_icon in
session) start_icon="#S" ;;
window) start_icon="#W" ;;
esac
first_plugin=${lplugins[0]}
IFS=' ' read -r -a first_colors <<<"$(get_plugin_colors "$first_plugin")"
2024-03-26 15:40:35 +05:30
tmux set-option -g status-left "#[bg=${!first_colors[0]},fg=${!first_colors[1]}]#{?client_prefix,#[bg=${light_yellow},} ${start_icon} "
2024-03-17 07:53:09 +05:30
}
status_bar() {
2024-03-17 02:57:19 +05:30
side=$1
if [ "$side" == "left" ]; then
plugins=("${lplugins[@]}")
else
plugins=("${rplugins[@]}")
fi
for plugin_index in "${!plugins[@]}"; do
plugin="${plugins[$plugin_index]}"
if [ -z "${plugin_colors[$plugin]}" ]; then
continue
fi
IFS=' ' read -r -a colors <<<"$(get_plugin_colors "$plugin")"
script="#($current_dir/$plugin.sh)"
if [ "$side" == "left" ]; then
if $show_powerline; then
next_plugin=${plugins[$((plugin_index + 1))]}
IFS=' ' read -r -a next_colors <<<"$(get_plugin_colors "$next_plugin")"
2024-03-17 07:53:09 +05:30
pl_bg=${!next_colors[0]:-$bg_main}
tmux set-option -ga status-left \
"#[fg=${!colors[1]},bg=${!colors[0]}] $script #[fg=${!colors[0]},bg=${pl_bg},nobold,nounderscore,noitalics]${l_sep}"
pl_bg=${bg_main}
2024-03-17 02:57:19 +05:30
else
tmux set-option -ga status-left "#[fg=${!colors[1]},bg=${!colors[0]}] $script "
fi
else
if $show_powerline; then
2024-03-17 07:53:09 +05:30
tmux set-option -ga status-right \
"#[fg=${!colors[0]},bg=${pl_bg},nobold,nounderscore,noitalics]${r_sep}#[fg=${!colors[1]},bg=${!colors[0]}] $script "
pl_bg=${!colors[0]}
2024-03-17 02:57:19 +05:30
else
tmux set-option -ga status-right "#[fg=${!colors[1]},bg=${!colors[0]}] $script "
fi
fi
done
}
2024-03-17 07:53:09 +05:30
window_list() {
IFS=' ' read -r -a colors <<<"$(get_plugin_colors "window")"
wbg=${!colors[0]}
wfg=${!colors[1]}
2024-04-02 11:09:50 +00:00
spacer=" "
if $compact; then
spacer=""
fi
2024-03-17 03:21:43 +05:30
if $show_flags; then
flags="#{?window_flags,#[fg=${light_red}]#{window_flags},}"
2024-03-17 08:12:59 +05:30
current_flags="#{?window_flags,#[fg=${light_green}]#{window_flags},}"
2024-03-17 03:21:43 +05:30
fi
2022-08-09 06:28:34 +05:30
if $show_powerline; then
2024-03-17 07:53:09 +05:30
tmux set-window-option -g window-status-current-format \
2024-04-02 11:09:50 +00:00
"#[fg=${wfg},bg=${wbg}]${wl_sep}#[bg=${wfg}]${current_flags}#[fg=${wbg}]${spacer}#I:#W${spacer}#[fg=${wfg},bg=${wbg}]${wr_sep}"
2024-03-17 07:53:09 +05:30
tmux set-window-option -g window-status-format \
2024-04-02 11:09:50 +00:00
"#[fg=${bg_alt},bg=${wbg}]${wl_sep}#[bg=${bg_alt}]${flags}#[fg=${white}]${spacer}#I:#W${spacer}#[fg=${bg_alt},bg=${wbg}]${wr_sep}"
else
2024-04-02 11:09:50 +00:00
tmux set-window-option -g window-status-current-format "#[fg=${wbg},bg=${wfg}] #I:#W${spacer}${current_flags} "
tmux set-window-option -g window-status-format "#[fg=${white},bg=${bg_alt}] #I:#W${spacer}${flags} "
2022-08-09 06:28:34 +05:30
fi
if $icons_only; then
2024-04-02 11:09:50 +00:00
tmux set-window-option -g window-status-current-format "#[fg=${wbg},bg=${wfg}]${spacer}#I:#W${spacer}"
tmux set-window-option -g window-status-format "#[fg=${white},bg=${wfg}]${spacer}#I:#W${spacer}"
fi
2024-03-17 07:53:09 +05:30
}
2022-08-09 06:28:34 +05:30
2024-03-17 07:53:09 +05:30
main() {
2024-03-27 10:26:05 +05:30
set_theme
2024-03-17 07:53:09 +05:30
set_options
start_icon
status_bar "left"
window_list
status_bar "right"
2022-08-09 06:28:34 +05:30
}
main