From ba9b5a645ee9d836779057480fccd40b94cad6bb Mon Sep 17 00:00:00 2001 From: Erimus Date: Fri, 23 Jun 2023 14:39:45 +0800 Subject: [PATCH 1/7] Restructuring, No changes --- scripts/dracula.sh | 188 ++++++++++++++++++++++++++++----------------- 1 file changed, 118 insertions(+), 70 deletions(-) diff --git a/scripts/dracula.sh b/scripts/dracula.sh index af0b2224..5dd22920 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -6,29 +6,21 @@ current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" source $current_dir/utils.sh main() + +# # Main Structure +# - Color Pallette +# - Get Tmux Option Variables +# - General +# - For Left Icon +# - For Window +# - For Plugins +# - Left Icon Area +# - Window Area +# - Right Plugins Area + { - # set configuration option variables - terraform_label=$(get_tmux_option "@dracula-terraform-label" "") - show_fahrenheit=$(get_tmux_option "@dracula-show-fahrenheit" true) - show_location=$(get_tmux_option "@dracula-show-location" true) - fixed_location=$(get_tmux_option "@dracula-fixed-location") - show_powerline=$(get_tmux_option "@dracula-show-powerline" false) - show_flags=$(get_tmux_option "@dracula-show-flags" false) - show_left_icon=$(get_tmux_option "@dracula-show-left-icon" smiley) - show_left_icon_padding=$(get_tmux_option "@dracula-left-icon-padding" 1) - show_military=$(get_tmux_option "@dracula-military-time" false) - show_timezone=$(get_tmux_option "@dracula-show-timezone" true) - show_left_sep=$(get_tmux_option "@dracula-show-left-sep" ) - show_right_sep=$(get_tmux_option "@dracula-show-right-sep" ) - show_border_contrast=$(get_tmux_option "@dracula-border-contrast" false) - show_day_month=$(get_tmux_option "@dracula-day-month" false) - show_refresh=$(get_tmux_option "@dracula-refresh-rate" 5) - time_format=$(get_tmux_option "@dracula-time-format" "") - show_kubernetes_context_label=$(get_tmux_option "@dracula-kubernetes-context-label" "") - IFS=' ' read -r -a plugins <<< $(get_tmux_option "@dracula-plugins" "battery network weather") - show_empty_plugins=$(get_tmux_option "@dracula-show-empty-plugins" true) - # Dracula Color Pallette +# Dracula Color Pallette{ white='#f8f8f2' gray='#44475a' dark_gray='#282a36' @@ -40,7 +32,81 @@ main() red='#ff5555' pink='#ff79c6' yellow='#f1fa8c' +# } + + +# Get Tmux Option Variables { + + # general + show_powerline=$(get_tmux_option "@dracula-show-powerline" false) + show_left_sep=$(get_tmux_option "@dracula-show-left-sep" ) + show_right_sep=$(get_tmux_option "@dracula-show-right-sep" ) + show_border_contrast=$(get_tmux_option "@dracula-border-contrast" false) + + # left icon area + show_left_icon=$(get_tmux_option "@dracula-show-left-icon" smiley) + show_left_icon_padding=$(get_tmux_option "@dracula-left-icon-padding" 1) + + # window area + show_flags=$(get_tmux_option "@dracula-show-flags" false) + + # right plugins area + # plugins general + show_refresh=$(get_tmux_option "@dracula-refresh-rate" 5) + show_empty_plugins=$(get_tmux_option "@dracula-show-empty-plugins" true) + + # terraform + terraform_label=$(get_tmux_option "@dracula-terraform-label" "") + + # weather + show_fahrenheit=$(get_tmux_option "@dracula-show-fahrenheit" true) + show_location=$(get_tmux_option "@dracula-show-location" true) + fixed_location=$(get_tmux_option "@dracula-fixed-location") + + # time + show_military=$(get_tmux_option "@dracula-military-time" false) + show_timezone=$(get_tmux_option "@dracula-show-timezone" true) + show_day_month=$(get_tmux_option "@dracula-day-month" false) + time_format=$(get_tmux_option "@dracula-time-format" "") + + # kubernetes-context + show_kubernetes_context_label=$(get_tmux_option "@dracula-kubernetes-context-label" "") + IFS=' ' read -r -a plugins <<< $(get_tmux_option "@dracula-plugins" "battery network weather") +# } + + +# General Settings { + + # sets refresh interval to every 5 seconds + tmux set-option -g status-interval $show_refresh + + # Handle powerline option + if $show_powerline; then + right_sep="$show_right_sep" + left_sep="$show_left_sep" + fi + + # set length + tmux set-option -g status-left-length 100 + tmux set-option -g status-right-length 100 + + # pane border styling + if $show_border_contrast; then + tmux set-option -g pane-active-border-style "fg=${light_purple}" + else + tmux set-option -g pane-active-border-style "fg=${dark_purple}" + fi + tmux set-option -g pane-border-style "fg=${gray}" + + # message styling + tmux set-option -g message-style "bg=${gray},fg=${white}" + + # status bar + tmux set-option -g status-style "bg=${gray},fg=${white}" +# } + +# Left Icon Area { # Handle left icon configuration case $show_left_icon in smiley) @@ -60,20 +126,19 @@ main() fi left_icon="$left_icon$padding" - # Handle powerline option + # Status left if $show_powerline; then - right_sep="$show_right_sep" - left_sep="$show_left_sep" + tmux set-option -g status-left "#[bg=${green},fg=${dark_gray}]#{?client_prefix,#[bg=${yellow}],} ${left_icon} #[fg=${green},bg=${gray}]#{?client_prefix,#[fg=${yellow}],}${left_sep}" + powerbg=${gray} + else + tmux set-option -g status-left "#[bg=${green},fg=${dark_gray}]#{?client_prefix,#[bg=${yellow}],} ${left_icon}" fi +# } - # Set timezone unless hidden by configuration - case $show_timezone in - false) - timezone="";; - true) - timezone="#(date +%Z)";; - esac +# Window Area { + + # Handle window flags case $show_flags in false) flags="" @@ -83,44 +148,38 @@ main() current_flags="#{?window_flags,#[fg=${light_purple}]#{window_flags},}" esac - # sets refresh interval to every 5 seconds - tmux set-option -g status-interval $show_refresh - - # set the prefix + t time format - if $show_military; then - tmux set-option -g clock-mode-style 24 + # Window option + if $show_powerline; then + tmux set-window-option -g window-status-current-format "#[fg=${gray},bg=${dark_purple}]${left_sep}#[fg=${white},bg=${dark_purple}] #I #W${current_flags} #[fg=${dark_purple},bg=${gray}]${left_sep}" else - tmux set-option -g clock-mode-style 12 + tmux set-window-option -g window-status-current-format "#[fg=${white},bg=${dark_purple}] #I #W${current_flags} " fi - # set length - tmux set-option -g status-left-length 100 - tmux set-option -g status-right-length 100 + tmux set-window-option -g window-status-format "#[fg=${white}]#[bg=${gray}] #I #W${flags}" - # pane border styling - if $show_border_contrast; then - tmux set-option -g pane-active-border-style "fg=${light_purple}" - else - tmux set-option -g pane-active-border-style "fg=${dark_purple}" - fi - tmux set-option -g pane-border-style "fg=${gray}" + tmux set-window-option -g window-status-activity-style "bold" + tmux set-window-option -g window-status-bell-style "bold" - # message styling - tmux set-option -g message-style "bg=${gray},fg=${white}" +# } - # status bar - tmux set-option -g status-style "bg=${gray},fg=${white}" +# Right Plugins Area{ + tmux set-option -g status-right "" - # Status left - if $show_powerline; then - tmux set-option -g status-left "#[bg=${green},fg=${dark_gray}]#{?client_prefix,#[bg=${yellow}],} ${left_icon} #[fg=${green},bg=${gray}]#{?client_prefix,#[fg=${yellow}],}${left_sep}" - powerbg=${gray} + # Set timezone unless hidden by configuration + case $show_timezone in + false) + timezone="";; + true) + timezone="#(date +%Z)";; + esac + + # set the prefix + t time format + if $show_military; then + tmux set-option -g clock-mode-style 24 else - tmux set-option -g status-left "#[bg=${green},fg=${dark_gray}]#{?client_prefix,#[bg=${yellow}],} ${left_icon}" + tmux set-option -g clock-mode-style 12 fi - # Status right - tmux set-option -g status-right "" for plugin in "${plugins[@]}"; do @@ -241,17 +300,6 @@ main() fi fi done - - # Window option - if $show_powerline; then - tmux set-window-option -g window-status-current-format "#[fg=${gray},bg=${dark_purple}]${left_sep}#[fg=${white},bg=${dark_purple}] #I #W${current_flags} #[fg=${dark_purple},bg=${gray}]${left_sep}" - else - tmux set-window-option -g window-status-current-format "#[fg=${white},bg=${dark_purple}] #I #W${current_flags} " - fi - - tmux set-window-option -g window-status-format "#[fg=${white}]#[bg=${gray}] #I #W${flags}" - tmux set-window-option -g window-status-activity-style "bold" - tmux set-window-option -g window-status-bell-style "bold" } # run main function From f0201e496abf303816950198f038c4797d0ec2cd Mon Sep 17 00:00:00 2001 From: Erimus Date: Fri, 23 Jun 2023 14:58:57 +0800 Subject: [PATCH 2/7] Improve Left Icon & Unify show powerline - Add padding & margin - Add customized color for prefix status - Remove too many if, and standardize the logic for enabling or disabling powerline. - status_bg -> variable --- scripts/dracula.sh | 67 +++++++++++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 21 deletions(-) diff --git a/scripts/dracula.sh b/scripts/dracula.sh index 5dd22920..705459bf 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -6,6 +6,7 @@ current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" source $current_dir/utils.sh main() +{ # # Main Structure # - Color Pallette @@ -18,7 +19,6 @@ main() # - Window Area # - Right Plugins Area -{ # Dracula Color Pallette{ white='#f8f8f2' @@ -42,13 +42,21 @@ main() show_left_sep=$(get_tmux_option "@dracula-show-left-sep" ) show_right_sep=$(get_tmux_option "@dracula-show-right-sep" ) show_border_contrast=$(get_tmux_option "@dracula-border-contrast" false) + status_bg=$(get_tmux_option "@dracula-status-bg" gray) # left icon area - show_left_icon=$(get_tmux_option "@dracula-show-left-icon" smiley) - show_left_icon_padding=$(get_tmux_option "@dracula-left-icon-padding" 1) + left_icon=$(get_tmux_option "@dracula-show-left-icon" smiley) + left_icon_bg=$(get_tmux_option "@dracula-left-icon-bg" green) + left_icon_fg=$(get_tmux_option "@dracula-left-icon-fg" dark_gray) + left_icon_prefix_bg=$(get_tmux_option "@dracula-left-icon-prefix-on-bg" red) + left_icon_prefix_fg=$(get_tmux_option "@dracula-left-icon-prefix-on-fg" white) + left_icon_padding_left=$(get_tmux_option "@dracula-left-icon-padding-left" 1) + left_icon_padding_right=$(get_tmux_option "@dracula-left-icon-padding-right" 1) + left_icon_margin_right=$(get_tmux_option "@dracula-left-icon-margin-right" 1) # window area show_flags=$(get_tmux_option "@dracula-show-flags" false) + IFS=' ' read -r -a plugins <<< $(get_tmux_option "@dracula-plugins" "battery network weather") # right plugins area # plugins general @@ -71,7 +79,6 @@ main() # kubernetes-context show_kubernetes_context_label=$(get_tmux_option "@dracula-kubernetes-context-label" "") - IFS=' ' read -r -a plugins <<< $(get_tmux_option "@dracula-plugins" "battery network weather") # } @@ -82,8 +89,13 @@ main() # Handle powerline option if $show_powerline; then - right_sep="$show_right_sep" left_sep="$show_left_sep" + right_sep="$show_right_sep" + else # if disable powerline mark, equal to '', unify the logic of string. + left_sep='' + right_sep='' + window_left_sep='' + window_right_sep='' fi # set length @@ -102,37 +114,50 @@ main() tmux set-option -g message-style "bg=${gray},fg=${white}" # status bar - tmux set-option -g status-style "bg=${gray},fg=${white}" + tmux set-option -g status-style "bg=${!status_bg},fg=${white}" # } # Left Icon Area { # Handle left icon configuration - case $show_left_icon in + case $left_icon in smiley) - left_icon="☺";; + left_icon_content="☺";; session) - left_icon="#S";; + left_icon_content="#S";; window) - left_icon="#W";; + left_icon_content="#W";; *) - left_icon=$show_left_icon;; + left_icon_content=$left_icon;; esac # Handle left icon padding - padding="" - if [ "$show_left_icon_padding" -gt "0" ]; then - padding="$(printf '%*s' $show_left_icon_padding)" + icon_pd_l="" + if [ "$left_icon_padding_left" -gt "0" ]; then + icon_pd_l="$(printf '%*s' $left_icon_padding_left)" + fi + icon_pd_r="" + if [ "$left_icon_padding_right" -gt "0" ]; then + icon_pd_r="$(printf '%*s' $left_icon_padding_right)" fi - left_icon="$left_icon$padding" - # Status left - if $show_powerline; then - tmux set-option -g status-left "#[bg=${green},fg=${dark_gray}]#{?client_prefix,#[bg=${yellow}],} ${left_icon} #[fg=${green},bg=${gray}]#{?client_prefix,#[fg=${yellow}],}${left_sep}" - powerbg=${gray} - else - tmux set-option -g status-left "#[bg=${green},fg=${dark_gray}]#{?client_prefix,#[bg=${yellow}],} ${left_icon}" + # Handle left icon margin + icon_mg_r="" + if [ "$left_icon_margin_right" -gt "0" ]; then + icon_mg_r="$(printf '%*s' $left_icon_margin_right)" fi + + # Left icon, with prefix status + tmux set-option -g status-left "\ +#{?client_prefix,#[fg=${!left_icon_prefix_fg}],#[fg=${!left_icon_fg}]}\ +#{?client_prefix,#[bg=${!left_icon_prefix_bg}],#[bg=${!left_icon_bg}]}\ +${icon_pd_l}${left_icon_content}${icon_pd_r}\ +#{?client_prefix,#[fg=${!left_icon_prefix_bg}],#[fg=${!left_icon_bg}]}\ +#[bg=${!status_bg}]\ +${left_sep}\ +${icon_mg_r}" + powerbg=${!status_bg} + # } From 0aeef241589b7bff04ba1c820075a7b240207720 Mon Sep 17 00:00:00 2001 From: Erimus Date: Fri, 23 Jun 2023 15:16:11 +0800 Subject: [PATCH 3/7] Improve window area - Customize color - Customize separator (can invert left sep color) - Customize padding & margin - Remove color of flags (follow the fg) - The window tab will maintain a consistent width regardless of focus. (Zoom and flags will change the width) --- scripts/dracula.sh | 74 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 62 insertions(+), 12 deletions(-) diff --git a/scripts/dracula.sh b/scripts/dracula.sh index 705459bf..2b81ffa8 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -56,12 +56,23 @@ main() # window area show_flags=$(get_tmux_option "@dracula-show-flags" false) - IFS=' ' read -r -a plugins <<< $(get_tmux_option "@dracula-plugins" "battery network weather") + window_bg=$(get_tmux_option "@dracula-window-bg" gray) + window_fg=$(get_tmux_option "@dracula-window-fg" white) + window_current_bg=$(get_tmux_option "@dracula-window-current-bg" dark_purple) + window_current_fg=$(get_tmux_option "@dracula-window-current-fg" white) + window_padding_left=$(get_tmux_option "@dracula-window-padding-left" 1) + window_padding_right=$(get_tmux_option "@dracula-window-padding-right" 1) + window_margin_right=$(get_tmux_option "@dracula-window-margin-right" 0) + window_left_sep=$(get_tmux_option "@dracula-window-left-sep" "") + window_right_sep=$(get_tmux_option "@dracula-window-right-sep" "") + window_left_sep_invert=$(get_tmux_option "@dracula-window-left-sep-invert" true) + window_disabled=$(get_tmux_option "@dracula-window-disabled" false) # right plugins area # plugins general show_refresh=$(get_tmux_option "@dracula-refresh-rate" 5) show_empty_plugins=$(get_tmux_option "@dracula-show-empty-plugins" true) + IFS=' ' read -r -a plugins <<< $(get_tmux_option "@dracula-plugins" "battery network weather") # terraform terraform_label=$(get_tmux_option "@dracula-terraform-label" "") @@ -163,25 +174,64 @@ ${icon_mg_r}" # Window Area { + # Handle window tabs padding & margin + win_pd_l="" + if [ "$window_padding_left" -gt "0" ]; then + win_pd_l="$(printf '%*s' $window_padding_left)" + fi + win_pd_r="" + if [ "$window_padding_right" -gt "0" ]; then + win_pd_r="$(printf '%*s' $window_padding_right)" + fi + win_mg_r="" + if [ "$window_margin_right" -gt "0" ]; then + win_mg_r="$(printf '%*s' $window_margin_right)" + fi + + # Handle window sep mark + # If window's separator not set, use the general separators. + if [ "$window_left_sep" = "" ]; then + window_left_sep=$left_sep + fi + if [ "$window_right_sep" = "" ]; then + window_right_sep=$left_sep + fi + + # Handle left separator if invert color + if $window_left_sep_invert; then + win_left_sep="#[bg=${!window_bg},fg=${!status_bg}]${window_left_sep}" + win_current_left_sep="#[bg=${!window_current_bg},fg=${!status_bg}]${window_left_sep}" + else + win_left_sep="#[bg=${!status_bg},fg=${!window_bg}]${window_left_sep}" + win_current_left_sep="#[bg=${!status_bg},fg=${!window_current_bg}]${window_left_sep}" + fi + # Handle window flags case $show_flags in false) - flags="" - current_flags="";; + win_flags="";; true) - flags="#{?window_flags,#[fg=${dark_purple}]#{window_flags},}" - current_flags="#{?window_flags,#[fg=${light_purple}]#{window_flags},}" + win_flags=" #{?window_flags,#{window_flags},}";; esac - # Window option - if $show_powerline; then - tmux set-window-option -g window-status-current-format "#[fg=${gray},bg=${dark_purple}]${left_sep}#[fg=${white},bg=${dark_purple}] #I #W${current_flags} #[fg=${dark_purple},bg=${gray}]${left_sep}" - else - tmux set-window-option -g window-status-current-format "#[fg=${white},bg=${dark_purple}] #I #W${current_flags} " + # Merge window tab + # If window disable, window won't be set, you can set it in tmux.conf. + if ! $window_disabled; then + tmux set-window-option -g window-status-format "\ +#[nobold,nounderscore,noitalics]\ +${win_left_sep}\ +#[fg=${!window_fg},bg=${!window_bg}]\ +${win_pd_l}#I #W${win_flags}${win_pd_r}\ +#[fg=${!window_bg},bg=${!status_bg}]${window_right_sep}${win_mg_r}" + + tmux set-window-option -g window-status-current-format "\ +#[nobold,nounderscore,noitalics]\ +${win_current_left_sep}\ +#[fg=${!window_current_fg},bg=${!window_current_bg}]\ +${win_pd_l}#I #W${win_flags}${win_pd_r}\ +#[fg=${!window_current_bg},bg=${!status_bg}]${window_right_sep}${win_mg_r}" fi - tmux set-window-option -g window-status-format "#[fg=${white}]#[bg=${gray}] #I #W${flags}" - tmux set-window-option -g window-status-activity-style "bold" tmux set-window-option -g window-status-bell-style "bold" From 7603b10efff0c95bfee0b3c1a25eb4430c797754 Mon Sep 17 00:00:00 2001 From: Erimus Date: Fri, 23 Jun 2023 15:32:45 +0800 Subject: [PATCH 4/7] Improve Plugins Area - Customize each side padding (rightmost separately) - Fix the padding of the timezone string --- scripts/dracula.sh | 69 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 18 deletions(-) diff --git a/scripts/dracula.sh b/scripts/dracula.sh index 2b81ffa8..094a1e99 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -74,6 +74,10 @@ main() show_empty_plugins=$(get_tmux_option "@dracula-show-empty-plugins" true) IFS=' ' read -r -a plugins <<< $(get_tmux_option "@dracula-plugins" "battery network weather") + plugin_padding_left=$(get_tmux_option "@dracula-plugin-padding-left" 1) + plugin_padding_right=$(get_tmux_option "@dracula-plugin-padding-right" 1) + plugin_padding_rightmost=$(get_tmux_option "@dracula-plugin-padding-rightmost" 1) + # terraform terraform_label=$(get_tmux_option "@dracula-terraform-label" "") @@ -237,15 +241,30 @@ ${win_pd_l}#I #W${win_flags}${win_pd_r}\ # } + # Right Plugins Area{ - tmux set-option -g status-right "" + tmux set-option -g status-right "" # reset + + # Handle plugins padding + plugin_pd_l="" + if [ "$plugin_padding_left" -gt "0" ]; then + plugin_pd_l="$(printf '%*s' $plugin_padding_left)" + fi + plugin_pd_r="" + if [ "$plugin_padding_right" -gt "0" ]; then + plugin_pd_r="$(printf '%*s' $plugin_padding_right)" + fi + plugin_pd_rm="" + if [ "$plugin_padding_rightmost" -gt "0" ]; then + plugin_pd_rm="$(printf '%*s' $plugin_padding_rightmost)" + fi # Set timezone unless hidden by configuration case $show_timezone in false) timezone="";; true) - timezone="#(date +%Z)";; + timezone=" #(date +%Z)";; esac # set the prefix + t time format @@ -255,8 +274,13 @@ ${win_pd_l}#I #W${win_flags}${win_pd_r}\ tmux set-option -g clock-mode-style 12 fi + # Prepare for handle last one + length=${#plugins[@]} + index=0 # counter + # Loop add plugins for plugin in "${plugins[@]}"; do + index=$((index + 1)) # count if case $plugin in custom:*) true;; *) false;; esac; then script=${plugin#"custom:"} @@ -346,13 +370,13 @@ ${win_pd_l}#I #W${win_flags}${win_pd_r}\ script=${time_format} else if $show_day_month && $show_military ; then # military time and dd/mm - script="%a %d/%m %R ${timezone} " + script="%a %d/%m %R${timezone}" elif $show_military; then # only military time - script="%a %m/%d %R ${timezone} " + script="%a %m/%d %R${timezone}" elif $show_day_month; then # only dd/mm - script="%a %d/%m %I:%M %p ${timezone} " + script="%a %d/%m %I:%M %p${timezone}" else - script="%a %m/%d %I:%M %p ${timezone} " + script="%a %m/%d %I:%M %p${timezone}" fi fi @@ -360,21 +384,30 @@ ${win_pd_l}#I #W${win_flags}${win_pd_r}\ continue fi - if $show_powerline; then - if $show_empty_plugins; then - tmux set-option -ga status-right "#[fg=${!colors[0]},bg=${powerbg},nobold,nounderscore,noitalics]${right_sep}#[fg=${!colors[1]},bg=${!colors[0]}] $script " - else - tmux set-option -ga status-right "#{?#{==:$script,},,#[fg=${!colors[0]},nobold,nounderscore,noitalics]${right_sep}#[fg=${!colors[1]},bg=${!colors[0]}] $script }" - fi - powerbg=${!colors[0]} + # Last one padding right + if [[ "$index" -eq "$length" ]]; then + pd_r=$plugin_pd_rm else - if $show_empty_plugins; then - tmux set-option -ga status-right "#[fg=${!colors[1]},bg=${!colors[0]}] $script " - else - tmux set-option -ga status-right "#{?#{==:$script,},,#[fg=${!colors[1]},bg=${!colors[0]}] $script }" - fi + pd_r=$plugin_pd_r + fi + + # Merge plugin + if $show_empty_plugins; then + tmux set-option -ga status-right "\ +#[fg=${!colors[0]},bg=${powerbg}nobold,nounderscore,noitalics]\ +${right_sep}#[fg=${!colors[1]},bg=${!colors[0]}]\ +${plugin_pd_l}$script${pd_r}" + else + tmux set-option -ga status-right "\ +#{?#{==:$script,},,#[fg=${!colors[0]},nobold,nounderscore,noitalics]\ +${right_sep}#[fg=${!colors[1]},bg=${!colors[0]}]\ +${plugin_pd_l}$script${pd_r}}" fi +#[nobold,nounderscore,noitalics]\ + powerbg=${!colors[0]} + done +# } } # run main function From a5967eae41686e40f61ff0407ea830bf7760e378 Mon Sep 17 00:00:00 2001 From: Erimus Date: Fri, 23 Jun 2023 16:06:46 +0800 Subject: [PATCH 5/7] Change the display of percentage - Add length limit (for integer) - Default align to right (number should align to right, align center makes right padding without control) --- scripts/cpu_info.sh | 4 +++- scripts/utils.sh | 26 ++++++++++++++++++++------ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/scripts/cpu_info.sh b/scripts/cpu_info.sh index b73db09a..cf33f99d 100755 --- a/scripts/cpu_info.sh +++ b/scripts/cpu_info.sh @@ -18,7 +18,9 @@ get_percent() cpucores=$(sysctl -n hw.logicalcpu) cpuusage=$(( cpuvalue / cpucores )) percent="$cpuusage%" - normalize_percent_len $percent + # a/b will get a integer, no decimal, like "1%" or "99%". + # So set the length to 3 below. + normalize_percent_len $percent 3 ;; CYGWIN*|MINGW32*|MSYS*|MINGW*) diff --git a/scripts/utils.sh b/scripts/utils.sh index a296192d..681f438f 100644 --- a/scripts/utils.sh +++ b/scripts/utils.sh @@ -11,15 +11,29 @@ get_tmux_option() { fi } -# normalize the percentage string to always have a length of 5 +# normalize the percentage string to customize length and align +# $1 percentage string +# $2 max length, default is 3 (99%) +# $3 align (left, center, right), default is right normalize_percent_len() { - # the max length that the percent can reach, which happens for a two digit number with a decimal house: "99.9%" - max_len=5 + # the max length that the percent can reach, which happens for a two digit number with a decimal house: "99.9%". percent_len=${#1} + max_len=${2:-5} # default + align=${3:-'right'} let diff_len=$max_len-$percent_len - # if the diff_len is even, left will have 1 more space than right - let left_spaces=($diff_len+1)/2 - let right_spaces=($diff_len)/2 + case $align in + 'center') + # if the diff_len is even, left will have 1 more space than right + let left_spaces=($diff_len+1)/2 + let right_spaces=($diff_len)/2;; + 'left') + let left_spaces=0 + let right_spaces=$diff_len;; + 'right') + let left_spaces=$diff_len + let right_spaces=0;; + esac + printf "%${left_spaces}s%s%${right_spaces}s\n" "" $1 "" } From 866e403e46fd532c16090e6e1595c987e2a64786 Mon Sep 17 00:00:00 2001 From: Erimus Date: Fri, 23 Jun 2023 16:29:51 +0800 Subject: [PATCH 6/7] Plugin - ping: add label & truncate integer --- scripts/network_ping.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/network_ping.sh b/scripts/network_ping.sh index 442f6be4..64aba167 100755 --- a/scripts/network_ping.sh +++ b/scripts/network_ping.sh @@ -15,7 +15,7 @@ ping_function() { # storing the hostname/IP in the variable PINGSERVER, default is google.com pingserver=$(get_tmux_option "@dracula-ping-server" "google.com") pingtime=$(ping -c 1 "$pingserver" | tail -1 | awk '{print $4}' | cut -d '/' -f 2) - echo "$pingtime ms" + echo "${pingtime%.*}ms" # Truncate the integer part ;; CYGWIN* | MINGW32* | MSYS* | MINGW*) @@ -26,7 +26,10 @@ ping_function() { main() { - echo $(ping_function) + # Label Ref            + ping_label=$(get_tmux_option "@dracula-ping-label" "Ping") + echo "$ping_label $(ping_function)" + RATE=$(get_tmux_option "@dracula-ping-rate" 5) sleep $RATE } From 158e68fac4d18881019bc6530dd565d2b366abc1 Mon Sep 17 00:00:00 2001 From: Erimus Date: Fri, 23 Jun 2023 16:40:58 +0800 Subject: [PATCH 7/7] Use utils/normalize_percent_len in more plugins, rename to normalize_string_length --- scripts/cpu_info.sh | 4 ++-- scripts/gpu_power.sh | 2 +- scripts/gpu_ram_info.sh | 2 +- scripts/gpu_usage.sh | 2 +- scripts/network_ping.sh | 4 +++- scripts/utils.sh | 2 +- 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/scripts/cpu_info.sh b/scripts/cpu_info.sh index cf33f99d..482612b1 100755 --- a/scripts/cpu_info.sh +++ b/scripts/cpu_info.sh @@ -10,7 +10,7 @@ get_percent() case $(uname -s) in Linux) percent=$(LC_NUMERIC=en_US.UTF-8 top -bn2 -d 0.01 | grep "Cpu(s)" | tail -1 | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1"%"}') - normalize_percent_len $percent + normalize_string_length $percent ;; Darwin) @@ -20,7 +20,7 @@ get_percent() percent="$cpuusage%" # a/b will get a integer, no decimal, like "1%" or "99%". # So set the length to 3 below. - normalize_percent_len $percent 3 + normalize_string_length $percent 3 ;; CYGWIN*|MINGW32*|MSYS*|MINGW*) diff --git a/scripts/gpu_power.sh b/scripts/gpu_power.sh index c97e6ee6..fd46e530 100755 --- a/scripts/gpu_power.sh +++ b/scripts/gpu_power.sh @@ -32,7 +32,7 @@ get_gpu() else usage='unknown' fi - normalize_percent_len $usage + normalize_string_length $usage } main() diff --git a/scripts/gpu_ram_info.sh b/scripts/gpu_ram_info.sh index 07de6dfa..e8f83883 100755 --- a/scripts/gpu_ram_info.sh +++ b/scripts/gpu_ram_info.sh @@ -31,7 +31,7 @@ get_gpu() else usage='unknown' fi - normalize_percent_len $usage + normalize_string_length $usage } main() diff --git a/scripts/gpu_usage.sh b/scripts/gpu_usage.sh index 552ed2b7..d3d4964f 100755 --- a/scripts/gpu_usage.sh +++ b/scripts/gpu_usage.sh @@ -31,7 +31,7 @@ get_gpu() else usage='unknown' fi - normalize_percent_len $usage + normalize_string_length $usage } main() diff --git a/scripts/network_ping.sh b/scripts/network_ping.sh index 64aba167..de0d5d05 100755 --- a/scripts/network_ping.sh +++ b/scripts/network_ping.sh @@ -15,7 +15,9 @@ ping_function() { # storing the hostname/IP in the variable PINGSERVER, default is google.com pingserver=$(get_tmux_option "@dracula-ping-server" "google.com") pingtime=$(ping -c 1 "$pingserver" | tail -1 | awk '{print $4}' | cut -d '/' -f 2) - echo "${pingtime%.*}ms" # Truncate the integer part + # Truncate the integer part + # Network ping doesn't always stable, so keep min length to 5(999ms). + normalize_string_length "${pingtime%.*}ms" 5 ;; CYGWIN* | MINGW32* | MSYS* | MINGW*) diff --git a/scripts/utils.sh b/scripts/utils.sh index 681f438f..bdc1fbe8 100644 --- a/scripts/utils.sh +++ b/scripts/utils.sh @@ -15,7 +15,7 @@ get_tmux_option() { # $1 percentage string # $2 max length, default is 3 (99%) # $3 align (left, center, right), default is right -normalize_percent_len() { +normalize_string_length() { # the max length that the percent can reach, which happens for a two digit number with a decimal house: "99.9%". percent_len=${#1} max_len=${2:-5} # default