Skip to content

Commit

Permalink
Merge pull request #138 from JannoTjarks/synchronize-panes
Browse files Browse the repository at this point in the history
Added plugin for the window option "Synchronize panes"
  • Loading branch information
ethancedwards8 committed Jul 12, 2023
2 parents bd87fa7 + 7c38079 commit ef42ec6
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 3 deletions.
12 changes: 9 additions & 3 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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, tmux-ram-usage, network, network-bandwidth, network-ping, attached-clients, network-vpn, weather, time, spotify-tui, kubernetes-context
# available plugins: battery, cpu-usage, git, gpu-usage, ram-usage, tmux-ram-usage, network, network-bandwidth, network-ping, attached-clients, network-vpn, weather, time, spotify-tui, kubernetes-context, synchronize-panes

set -g @dracula-plugins "cpu-usage gpu-usage ram-usage"
```
Expand Down Expand Up @@ -298,6 +298,13 @@ Hide your location
set -g @dracula-show-location false
```

#### synchronize-panes options

Customize label

```bash
set -g @dracula-synchronize-panes-label "Sync"
```
#### attached-clients options

Set the minimum number of clients to show (otherwise, show nothing)
Expand All @@ -311,5 +318,4 @@ Set the label when there is one client, or more than one client
```bash
set -g @dracula-clients-singular client
set -g @dracula-clients-plural clients
```

```
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,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
- Spotify playback (needs the tool spotify-tui installed)
- Current kubernetes context
- Current working directory of tmux pane
Expand Down
6 changes: 6 additions & 0 deletions scripts/dracula.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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")
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")
Expand Down Expand Up @@ -234,6 +235,11 @@ main()
else
continue
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
if $show_empty_plugins; then
Expand Down
26 changes: 26 additions & 0 deletions scripts/synchronize_panes.sh
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions scripts/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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%"
Expand Down

0 comments on commit ef42ec6

Please sign in to comment.