feat(modules): extract all ui components into independend modules

This commit is contained in:
Valentin Uveges 2023-08-06 20:51:23 +03:00
parent a436f766cb
commit 56a447094a
14 changed files with 274 additions and 200 deletions

View file

@ -40,6 +40,7 @@ load_modules() {
local modules_array
read -a modules_array <<< "$modules_list"
local module_index=0;
local module_name
for module_name in ${modules_array[@]}
do
@ -48,7 +49,8 @@ load_modules() {
if [[ 0 -eq $? ]]
then
loaded_modules=$loaded_modules$( show_$module_name )
loaded_modules="$loaded_modules$( show_$module_name $module_index )"
module_index=$module_index+1
fi
done
@ -90,150 +92,30 @@ main() {
# --------=== Statusline
# NOTE: Checking for the value of @catppuccin_window_tabs_enabled
local wt_enabled
wt_enabled="$(get_tmux_option "@catppuccin_window_tabs_enabled" "off")"
readonly wt_enabled
local window_left_separator="$(get_tmux_option "@catppuccin_window_left_separator" "█")"
local window_right_separator="$(get_tmux_option "@catppuccin_window_right_separator" "█")"
local window_middle_separator="$(get_tmux_option "@catppuccin_window_middle_separator" "█")"
local window_color_fill="$(get_tmux_option "@catppuccin_window_color_fill" "number")"
local window_icon_position="$(get_tmux_option "@catppuccin_window_icon_position" "right")"
local pill_theme_enabled
pill_theme_enabled="$(get_tmux_option "@catppuccin_pill_theme_enabled" "off")"
readonly pill_theme_enabled
local window_module="$(get_tmux_option "@catppuccin_window_module" "directory_in_window")"
local window_current_module="$(get_tmux_option "@catppuccin_window_current_module" "directory_in_window_current")"
local powerline_theme_enabled
powerline_theme_enabled="$(get_tmux_option "@catppuccin_powerline_theme_enabled" "off")"
readonly powerline_theme_enabled
local window_format=$( load_modules "$PLUGIN_DIR/window" "$window_module")
local window_current_format=$( load_modules "$PLUGIN_DIR/window" "$window_current_module")
local powerline_icons_theme_enabled
powerline_icons_theme_enabled="$(get_tmux_option "@catppuccin_powerline_icons_theme_enabled" "off")"
readonly powerline_icons_theme_enabled
setw window-status-format "${window_format}"
setw window-status-current-format "${window_current_format}"
local no_patched_fonts_theme_enabled
no_patched_fonts_theme_enabled="$(get_tmux_option "@catppuccin_no_patched_fonts_theme_enabled" "off")"
readonly no_patched_fonts_theme_enabled
local status_left_separator="$(get_tmux_option "@catppuccin_status_left_separator" " ")"
local status_right_separator="$(get_tmux_option "@catppuccin_status_right_separator" "█")"
local status_connect_separator="$(get_tmux_option "@catppuccin_status_connect_separator" "yes")"
# Separators for the left status / window list
local l_left_separator
l_left_separator="$(get_tmux_option "@catppuccin_l_left_separator" "")"
readonly l_left_separator
local l_right_separator
l_right_separator="$(get_tmux_option "@catppuccin_l_right_separator" "")"
readonly l_right_separator
# Separators for the right status
local r_left_separator
r_left_separator="$(get_tmux_option "@catppuccin_r_left_separator" "")"
readonly r_left_separator
local r_right_separator
r_right_separator="$(get_tmux_option "@catppuccin_r_right_separator" "")"
readonly r_right_separator
local user
user="$(get_tmux_option "@catppuccin_user" "off")"
readonly user
local host
host="$(get_tmux_option "@catppuccin_host" "off")"
readonly host
local date_time
date_time="$(get_tmux_option "@catppuccin_date_time" "off")"
readonly date_time
# Icons
local directory_icon
directory_icon="$(get_tmux_option "@catppuccin_directory_icon" "")"
readonly directory_icon
local window_icon
window_icon="$(get_tmux_option "@catppuccin_window_icon" "")"
readonly window_icon
local session_icon
session_icon="$(get_tmux_option "@catppuccin_session_icon" "")"
readonly session_icon
local user_icon
user_icon="$(get_tmux_option "@catppuccin_user_icon" "")"
readonly user_icon
local host_icon
host_icon="$(get_tmux_option "@catppuccin_host_icon" "󰒋")"
readonly host_icon
local datetime_icon
datetime_icon="$(get_tmux_option "@catppuccin_datetime_icon" "")"
readonly datetime_icon
# Source status line themes
if [[ "${pill_theme_enabled}" == "off" ]] &&
[[ "${powerline_theme_enabled}" == "off" ]] &&
[[ "${powerline_icons_theme_enabled}" == "off" ]] &&
[[ "${no_patched_fonts_theme_enabled}" == "off" ]]; then
source "$PLUGIN_DIR/$DEFAULT_STATUS_LINE_FILE"
fi
if [[ "${pill_theme_enabled}" == "on" ]]; then
source "$PLUGIN_DIR/$PILL_STATUS_LINE_FILE"
fi
if [[ "${powerline_theme_enabled}" == "on" ]]; then
source "$PLUGIN_DIR/$POWERLINE_STATUS_LINE_FILE"
fi
if [[ "${powerline_icons_theme_enabled}" == "on" ]]; then
source "$PLUGIN_DIR/$POWERLINE_ICONS_STATUS_LINE_FILE"
fi
if [[ "${no_patched_fonts_theme_enabled}" == "on" ]]; then
source "$PLUGIN_DIR/$NO_PATCHED_FONTS_STATUS_LINE_FILE"
fi
# Right column 1 by default shows the Window name.
local right_column1=$show_window
# Right column 2 by default shows the current Session name.
local right_column2=$show_session
# Window status by default shows the current directory basename.
local window_status_format=$show_directory_in_window_status
local window_status_current_format=$show_directory_in_window_status_current
# NOTE: With the @catppuccin_window_tabs_enabled set to on, we're going to
# update the right_column1 and the window_status_* variables.
if [[ "${wt_enabled}" == "on" ]]; then
right_column1=$show_directory
window_status_format=$show_window_in_window_status
window_status_current_format=$show_window_in_window_status_current
fi
if [[ "${user}" == "on" ]]; then
right_column2="$right_column2$show_user"
fi
if [[ "${host}" == "on" ]]; then
right_column2="$right_column2$show_host"
fi
if [[ "${date_time}" != "off" ]]; then
right_column2="$right_column2$show_date_time"
fi
local status_modules="$(get_tmux_option "@catppuccin_status_modules" "application session")"
local loaded_modules=$( load_modules "$PLUGIN_DIR/status" "$status_modules")
set status-left ""
local status_left_separator=$r_left_separator
local status_right_separator=$l_right_separator
local status_modules="$(get_tmux_option "@catppuccin_status_modules" "")"
local loaded_modules=$( load_modules "$PLUGIN_DIR/modules" "$status_modules")
set status-right "${right_column1}${right_column2}${loaded_modules}"
setw window-status-format "${window_status_format}"
setw window-status-current-format "${window_status_current_format}"
set status-right "${loaded_modules}"
# --------=== Modes
#

View file

@ -1,14 +0,0 @@
show_date_time() {
local date_time_icon="$(get_tmux_option "@catppuccin_datetime_icon" "󰃰")"
local date_time_format="$(get_tmux_option "@catppuccin_date_time_format" "%Y-%m-%d %H:%M")"
local show_left_separator="#[fg=$thm_blue,bg=$thm_bg,nobold,nounderscore,noitalics]$status_left_separator"
local show_date_time_icon="#[fg=$thm_bg,bg=$thm_blue,nobold,nounderscore,noitalics]$datetime_icon"
local show_date_time_text="#[fg=$thm_fg,bg=$thm_gray]$date_time_format"
local show_right_separator="#[fg=$thm_gray,bg=$thm_bg,nobold,nounderscore,noitalics]$status_right_separator"
local show_date_time=$show_left_separator$show_date_time_icon" "$show_date_time_text$show_right_separator
echo $show_date_time
}

View file

@ -1,12 +1,3 @@
local show_directory
readonly show_directory="#[fg=$thm_pink,bg=$thm_bg,nobold,nounderscore,noitalics]$r_left_separator#[fg=$thm_bg,bg=$thm_pink,nobold,nounderscore,noitalics]$directory_icon #[fg=$thm_fg,bg=$thm_gray] #{b:pane_current_path} "
local show_window
readonly show_window="#[fg=$thm_pink,bg=$thm_bg,nobold,nounderscore,noitalics]$r_left_separator#[fg=$thm_bg,bg=$thm_pink,nobold,nounderscore,noitalics]$window_icon #[fg=$thm_fg,bg=$thm_gray] #W "
local show_session
readonly show_session="#[fg=$thm_green]#[bg=$thm_gray]#{?client_prefix,#[fg=$thm_red],#[fg=$thm_green]}$r_left_separator#{?client_prefix,#[bg=$thm_red],#[bg=$thm_green]}#[fg=$thm_bg]$session_icon #[fg=$thm_fg,bg=$thm_gray] #S "
local show_directory_in_window_status
readonly show_directory_in_window_status="#[fg=$thm_bg,bg=$thm_blue] #I #[fg=$thm_fg,bg=$thm_gray] #{b:pane_current_path} "
@ -18,12 +9,3 @@ readonly show_window_in_window_status="#[fg=$thm_fg,bg=$thm_bg] #W #[fg=$thm_bg,
local show_window_in_window_status_current
readonly show_window_in_window_status_current="#[fg=$thm_fg,bg=$thm_gray] #W #[fg=$thm_bg,bg=$thm_orange] #I#[fg=$thm_orange,bg=$thm_bg,nobold,nounderscore,noitalics]$l_right_separator "
local show_user
readonly show_user="#[fg=$thm_cyan,bg=$thm_gray,nobold,nounderscore,noitalics]$r_left_separator#[fg=$thm_bg,bg=$thm_cyan,nobold,nounderscore,noitalics]$user_icon #[fg=$thm_fg,bg=$thm_gray] #(whoami) "
local show_host
readonly show_host="#[fg=$thm_magenta,bg=$thm_gray,nobold,nounderscore,noitalics]$r_left_separator#[fg=$thm_bg,bg=$thm_magenta,nobold,nounderscore,noitalics]$host_icon #[fg=$thm_fg,bg=$thm_gray] #H "
local show_date_time
readonly show_date_time="#[fg=$thm_blue,bg=$thm_gray,nobold,nounderscore,noitalics]$r_left_separator#[fg=$thm_bg,bg=$thm_blue,nobold,nounderscore,noitalics]$datetime_icon #[fg=$thm_fg,bg=$thm_gray] $date_time "

16
status/application.sh Normal file
View file

@ -0,0 +1,16 @@
show_application() {
local icon="$(get_tmux_option "@catppuccin_application_icon" "")"
if [[ $1 -eq 0 || $status_connect_separator == "no" ]]
then
local show_left_separator="#[fg=$thm_pink,bg=$thm_bg,nobold,nounderscore,noitalics]$status_left_separator"
else
local show_left_separator="#[fg=$thm_pink,bg=$thm_gray,nobold,nounderscore,noitalics]$status_left_separator"
fi
local show_icon="#[fg=$thm_bg,bg=$thm_pink,nobold,nounderscore,noitalics]$icon "
local show_text="#[fg=$thm_fg,bg=$thm_gray] #W"
local show_right_separator="#[fg=$thm_gray,bg=$thm_bg,nobold,nounderscore,noitalics]$status_right_separator"
echo "$show_left_separator$show_icon$show_text$show_right_separator"
}

18
status/date_time.sh Normal file
View file

@ -0,0 +1,18 @@
show_date_time() {
local icon="$(get_tmux_option "@catppuccin_datetime_icon" "󰃰")"
local format="$(get_tmux_option "@catppuccin_date_time_format" "%Y-%m-%d %H:%M")"
if [[ $1 -eq 0 || $status_connect_separator == "no" ]]
then
local show_left_separator="#[fg=$thm_blue,bg=$thm_bg,nobold,nounderscore,noitalics]$status_left_separator"
else
local show_left_separator="#[fg=$thm_blue,bg=$thm_gray,nobold,nounderscore,noitalics]$status_left_separator"
fi
local show_icon="#[fg=$thm_bg,bg=$thm_blue,nobold,nounderscore,noitalics]$icon "
local show_text="#[fg=$thm_fg,bg=$thm_gray] $format"
local show_right_separator="#[fg=$thm_gray,bg=$thm_bg,nobold,nounderscore,noitalics]$status_right_separator"
echo "$show_left_separator$show_icon$show_text$show_right_separator"
}

16
status/directory.sh Normal file
View file

@ -0,0 +1,16 @@
show_directory() {
local icon="$(get_tmux_option "@catppuccin_directory_icon" "")"
if [[ $1 -eq 0 || $status_connect_separator == "no" ]]
then
local show_left_separator="#[fg=$thm_pink,bg=$thm_bg,nobold,nounderscore,noitalics]$status_left_separator"
else
local show_left_separator="#[fg=$thm_pink,bg=$thm_gray,nobold,nounderscore,noitalics]$status_left_separator"
fi
local show_icon="#[fg=$thm_bg,bg=$thm_pink,nobold,nounderscore,noitalics]$icon "
local show_text="#[fg=$thm_fg,bg=$thm_gray] #{b:pane_current_path}"
local show_right_separator="#[fg=$thm_gray,bg=$thm_bg,nobold,nounderscore,noitalics]$status_right_separator"
echo "$show_left_separator$show_icon$show_text$show_right_separator"
}

16
status/host.sh Normal file
View file

@ -0,0 +1,16 @@
show_host() {
local icon="$(get_tmux_option "@catppuccin_host_icon" "󰒋")"
if [[ $1 -eq 0 || $status_connect_separator == "no" ]]
then
local show_left_separator="#[fg=$thm_blue,bg=$thm_bg,nobold,nounderscore,noitalics]$status_left_separator"
else
local show_left_separator="#[fg=$thm_blue,bg=$thm_gray,nobold,nounderscore,noitalics]$status_left_separator"
fi
local show_icon="#[fg=$thm_bg,bg=$thm_blue,nobold,nounderscore,noitalics]$icon "
local show_text="#[fg=$thm_fg,bg=$thm_gray] #H"
local show_right_separator="#[fg=$thm_gray,bg=$thm_bg,nobold,nounderscore,noitalics]$status_right_separator"
echo "$show_left_separator$show_icon$show_text$show_right_separator"
}

16
status/session.sh Normal file
View file

@ -0,0 +1,16 @@
show_session() {
local icon="$(get_tmux_option "@catppuccin_session_icon" "")"
if [[ $1 -eq 0 || $status_connect_separator == "no" ]]
then
local show_left_separator="#[fg=$thm_green]#[bg=$thm_bg]#{?client_prefix,#[fg=$thm_red],#[fg=$thm_green]}$status_left_separator"
else
local show_left_separator="#[fg=$thm_green]#[bg=$thm_gray]#{?client_prefix,#[fg=$thm_red],#[fg=$thm_green]}$status_left_separator"
fi
local show_icon="#{?client_prefix,#[bg=$thm_red],#[bg=$thm_green]}#[fg=$thm_bg]$icon "
local show_text="#[fg=$thm_fg,bg=$thm_gray] #S"
local show_right_separator="#[fg=$thm_gray,bg=$thm_bg,nobold,nounderscore,noitalics]$status_right_separator"
echo "$show_left_separator$show_icon$show_text$show_right_separator"
}

16
status/user.sh Normal file
View file

@ -0,0 +1,16 @@
show_user() {
local icon="$(get_tmux_option "@catppuccin_user_icon" "")"
if [[ $1 -eq 0 || $status_connect_separator == "no" ]]
then
local show_left_separator="#[fg=$thm_blue,bg=$thm_bg,nobold,nounderscore,noitalics]$status_left_separator"
else
local show_left_separator="#[fg=$thm_blue,bg=$thm_gray,nobold,nounderscore,noitalics]$status_left_separator"
fi
local show_icon="#[fg=$thm_bg,bg=$thm_blue,nobold,nounderscore,noitalics]$icon "
local show_text="#[fg=$thm_fg,bg=$thm_gray] #(whoami)"
local show_right_separator="#[fg=$thm_gray,bg=$thm_bg,nobold,nounderscore,noitalics]$status_right_separator"
echo "$show_left_separator$show_icon$show_text$show_right_separator"
}

View file

@ -1,30 +0,0 @@
#!/bin/bash
load_modules() {
local loaded_modules
local modules_path=$1
local modules_list=$2
local modules_array
read -a modules_array <<< "$modules_list"
local module_name
for module_name in ${modules_array[@]}
do
local module_path=$modules_path/$module_name.sh
source $module_path
if [[ 0 -eq $? ]]
then
loaded_modules=$loaded_modules$( show_$module_name )
fi
done
echo $loaded_modules
}
module_path="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"/modules
module_list="user host date_time"
echo $( load_modules "$module_path" "$module_list" )

View file

@ -0,0 +1,37 @@
show_application_in_window() {
if [[ $window_color_fill == "number" ]]
then
local show_icon="#[fg=$thm_bg,bg=$thm_blue]#I"
local show_middle_separator="#[fg=$thm_blue,bg=$thm_gray,nobold,nounderscore,noitalics]$window_middle_separator"
local show_text="#[fg=$thm_fg,bg=$thm_gray]#W"
if [[ $window_icon_position == "right" ]]
then
local show_left_separator="#[fg=$thm_gray,bg=$thm_bg,nobold,nounderscore,noitalics]$window_left_separator"
local show_right_separator="#[fg=$thm_blue,bg=$thm_bg]$window_right_separator"
echo "$show_left_separator$show_text$show_middle_separator$show_icon$show_right_separator"
else
local show_left_separator="#[fg=$thm_blue,bg=$thm_bg,nobold,nounderscore,noitalics]$window_left_separator"
local show_right_separator="#[fg=$thm_gray,bg=$thm_bg]$window_right_separator"
echo "$show_left_separator$show_icon$show_middle_separator$show_text$show_right_separator"
fi
else
local show_left_separator="#[fg=$thm_blue,bg=$thm_bg,nobold,nounderscore,noitalics]$window_left_separator"
local show_icon="#[fg=$thm_bg,bg=$thm_blue]#I"
local show_middle_separator="#[fg=$thm_gray,bg=$thm_blue,nobold,nounderscore,noitalics]$window_middle_separator"
local show_text="#[fg=$thm_bg,bg=$thm_blue]#{b:pane_current_path}"
local show_right_separator="#[fg=$thm_blue,bg=$thm_bg]$window_right_separator"
if [[ $window_icon_position == "right" ]]
then
echo "$show_left_separator$show_text$show_middle_separator$show_icon$show_right_separator"
else
echo "$show_left_separator$show_icon$show_middle_separator$show_text$show_right_separator"
fi
fi
}

View file

@ -0,0 +1,40 @@
show_application_in_window_current() {
if [[ $window_color_fill == "number" ]]
then
local show_icon="#[fg=$thm_bg,bg=$thm_orange]#I"
local show_middle_separator="#[fg=$thm_orange,bg=$thm_bg,nobold,nounderscore,noitalics]$window_middle_separator"
local show_text="#[fg=$thm_fg,bg=$thm_bg]#W"
if [[ $window_icon_position == "right" ]]
then
local show_left_separator="#[fg=$thm_bg,bg=$thm_bg,nobold,nounderscore,noitalics]$window_left_separator"
local show_right_separator="#[fg=$thm_orange,bg=$thm_bg]$window_right_separator"
echo "$show_left_separator$show_text$show_middle_separator$show_icon$show_right_separator"
else
local show_left_separator="#[fg=$thm_orange,bg=$thm_bg,nobold,nounderscore,noitalics]$window_left_separator"
local show_right_separator="#[fg=$thm_bg,bg=$thm_bg]$window_right_separator"
echo "$show_left_separator$show_icon$show_middle_separator$show_text$show_right_separator"
fi
else
local show_left_separator="#[fg=$thm_orange,bg=$thm_bg,nobold,nounderscore,noitalics]$window_left_separator"
local show_icon="#[fg=$thm_bg,bg=$thm_orange]#I"
local show_middle_separator="#[fg=$thm_bg,bg=$thm_orange,nobold,nounderscore,noitalics]$window_middle_separator"
local show_text="#[fg=$thm_bg,bg=$thm_orange]#{b:pane_current_path}"
local show_right_separator="#[fg=$thm_orange,bg=$thm_bg]$window_right_separator"
if [[ $window_icon_position == "right" ]]
then
echo "$show_left_separator$show_text$show_middle_separator$show_icon$show_right_separator"
else
echo "$show_left_separator$show_icon$show_middle_separator$show_text$show_right_separator"
fi
fi
}

View file

@ -0,0 +1,38 @@
show_directory_in_window() {
if [[ $window_color_fill == "number" ]]
then
local show_icon="#[fg=$thm_bg,bg=$thm_blue]#I"
local show_middle_separator="#[fg=$thm_blue,bg=$thm_gray,nobold,nounderscore,noitalics]$window_middle_separator"
local show_text="#[fg=$thm_fg,bg=$thm_gray]#{b:pane_current_path}"
if [[ $window_icon_position == "right" ]]
then
local show_left_separator="#[fg=$thm_gray,bg=$thm_bg,nobold,nounderscore,noitalics]$window_left_separator"
local show_right_separator="#[fg=$thm_blue,bg=$thm_bg]$window_right_separator"
echo "$show_left_separator$show_text$show_middle_separator$show_icon$show_right_separator"
else
local show_left_separator="#[fg=$thm_blue,bg=$thm_bg,nobold,nounderscore,noitalics]$window_left_separator"
local show_right_separator="#[fg=$thm_gray,bg=$thm_bg]$window_right_separator"
echo "$show_left_separator$show_icon$show_middle_separator$show_text$show_right_separator"
fi
else
local show_left_separator="#[fg=$thm_blue,bg=$thm_bg,nobold,nounderscore,noitalics]$window_left_separator"
local show_icon="#[fg=$thm_bg,bg=$thm_blue]#I"
local show_middle_separator="#[fg=$thm_gray,bg=$thm_blue,nobold,nounderscore,noitalics]$window_middle_separator"
local show_text="#[fg=$thm_bg,bg=$thm_blue]#{b:pane_current_path}"
local show_right_separator="#[fg=$thm_blue,bg=$thm_bg]$window_right_separator"
if [[ $window_icon_position == "right" ]]
then
echo "$show_left_separator$show_text$show_middle_separator$show_icon$show_right_separator"
else
echo "$show_left_separator$show_icon$show_middle_separator$show_text$show_right_separator"
fi
fi
}

View file

@ -0,0 +1,41 @@
show_directory_in_window_current() {
if [[ $window_color_fill == "number" ]]
then
local show_icon="#[fg=$thm_bg,bg=$thm_orange]#I"
local show_middle_separator="#[fg=$thm_orange,bg=$thm_bg,nobold,nounderscore,noitalics]$window_middle_separator"
local show_text="#[fg=$thm_fg,bg=$thm_bg]#{b:pane_current_path}"
if [[ $window_icon_position == "right" ]]
then
local show_left_separator="#[fg=$thm_bg,bg=$thm_bg,nobold,nounderscore,noitalics]$window_left_separator"
local show_right_separator="#[fg=$thm_orange,bg=$thm_bg]$window_right_separator"
echo "$show_left_separator$show_text$show_middle_separator$show_icon$show_right_separator"
else
local show_left_separator="#[fg=$thm_orange,bg=$thm_bg,nobold,nounderscore,noitalics]$window_left_separator"
local show_right_separator="#[fg=$thm_bg,bg=$thm_bg]$window_right_separator"
echo "$show_left_separator$show_icon$show_middle_separator$show_text$show_right_separator"
fi
else
local show_left_separator="#[fg=$thm_orange,bg=$thm_bg,nobold,nounderscore,noitalics]$window_left_separator"
local show_icon="#[fg=$thm_bg,bg=$thm_orange]#I"
local show_middle_separator="#[fg=$thm_bg,bg=$thm_orange,nobold,nounderscore,noitalics]$window_middle_separator"
local show_text="#[fg=$thm_bg,bg=$thm_orange]#{b:pane_current_path}"
local show_right_separator="#[fg=$thm_orange,bg=$thm_bg]$window_right_separator"
if [[ $window_icon_position == "right" ]]
then
echo "$show_left_separator$show_text$show_middle_separator$show_icon$show_right_separator"
else
echo "$show_left_separator$show_icon$show_middle_separator$show_text$show_right_separator"
fi
fi
}