From 09a96946ff2117a80c4fd1ace248600bf73b19ff Mon Sep 17 00:00:00 2001 From: Janno Tjarks Date: Wed, 22 Dec 2021 22:50:05 +0100 Subject: [PATCH] Added synchronize-panes plugin --- INSTALL.md | 10 +++++++++- README.md | 1 + scripts/dracula.sh | 6 ++++++ scripts/synchronize_panes.sh | 26 ++++++++++++++++++++++++++ scripts/utils.sh | 11 +++++++++++ 5 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 scripts/synchronize_panes.sh diff --git a/INSTALL.md b/INSTALL.md index f6e915e..c0afd6f 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -48,7 +48,7 @@ To enable plugins set up the `@dracula-plugins` option in you `.tmux.conf` file, The order that you define the plugins will be the order on the status bar left to right. ```bash -# available plugins: battery, cpu-usage, git, gpu-usage, ram-usage, network, network-bandwidth, weather, time +# available plugins: battery, cpu-usage, git, gpu-usage, ram-usage, network, network-bandwidth, weather, time, synchronize-panes set -g @dracula-plugins "cpu-usage gpu-usage ram-usage" ``` @@ -189,3 +189,11 @@ Switch from default fahrenheit to celsius set -g @dracula-show-fahrenheit false ``` + +#### synchronize-panes options + +Customize label + +```bash +set -g @dracula-synchronize-panes-label "Sync" +``` diff --git a/README.md b/README.md index eef0aaa..af093ef 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ Configuration and options can be found at [draculatheme.com/tmux](https://dracul * When prefix is enabled smiley face turns from green to yellow * When charging, 'AC' is displayed * If forecast information is available, a ☀, ☁, ☂, or ❄ unicode character corresponding with the forecast is displayed alongside the temperature +* Info if the Panes are synchronized ## Compatibility diff --git a/scripts/dracula.sh b/scripts/dracula.sh index f530187..d82517b 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -23,6 +23,7 @@ main() 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) + show_synchronize_panes_label=$(get_tmux_option "@dracula-synchronize-panes-label" "Sync") IFS=' ' read -r -a plugins <<< $(get_tmux_option "@dracula-plugins" "battery network weather") # Dracula Color Pallette @@ -185,6 +186,11 @@ main() script="%a %m/%d %I:%M %p ${timezone} " fi fi + + if [ $plugin = "synchronize-panes" ]; then + IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-synchronize-panes-colors" "cyan dark_gray") + script="#($current_dir/synchronize_panes.sh $show_synchronize_panes_label)" + fi if $show_powerline; then tmux set-option -ga status-right "#[fg=${!colors[0]},bg=${powerbg},nobold,nounderscore,noitalics]${right_sep}#[fg=${!colors[1]},bg=${!colors[0]}] $script " diff --git a/scripts/synchronize_panes.sh b/scripts/synchronize_panes.sh new file mode 100644 index 0000000..078e8a9 --- /dev/null +++ b/scripts/synchronize_panes.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +# setting the locale, some users have issues with different locales, this forces the correct one +export LC_ALL=en_US.UTF-8 + +label=$1 + +current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +source $current_dir/utils.sh + +get_synchronize_panes_status() { + current_synchronize_panes_status=$(get_tmux_window_option "synchronize-panes" "off") + echo $current_synchronize_panes_status +} + +main() +{ + # storing the refresh rate in the variable RATE, default is 5 + RATE=$(get_tmux_option "@dracula-refresh-rate" 5) + synchronize_panes_label=$label + synchronize_panes_status=$(get_synchronize_panes_status) + echo "$synchronize_panes_label $synchronize_panes_status" + sleep $RATE +} + +# run main driver +main diff --git a/scripts/utils.sh b/scripts/utils.sh index a296192..b4402e6 100644 --- a/scripts/utils.sh +++ b/scripts/utils.sh @@ -11,6 +11,17 @@ get_tmux_option() { fi } +get_tmux_window_option() { + local option=$1 + local default_value=$2 + local option_value=$(tmux show-window-options -v "$option") + if [ -z "$option_value" ]; then + echo $default_value + else + echo $option_value + fi +} + # normalize the percentage string to always have a length of 5 normalize_percent_len() { # the max length that the percent can reach, which happens for a two digit number with a decimal house: "99.9%"