Skip to content

Commit 8d833fb

Browse files
Support synchronized panes prompt (tmux-plugins#19)
* Use -n instead of ! -z Following shellcheck recommendation SC2236 * Add support synchronized panes prompt
1 parent 8880f9c commit 8d833fb

File tree

2 files changed

+43
-15
lines changed

2 files changed

+43
-15
lines changed

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,25 @@ set -g @prefix_highlight_fg 'white' # default is 'colour231'
6262
set -g @prefix_highlight_bg 'blue' # default is 'colour04'
6363
```
6464

65-
The plugin can also be configured to show when copy mode is active. If enabled,
66-
the `#{prefix_highlight}` token will be replaced with the string `Copy` when
67-
copy mode is enabled. The style for copy mode can be configured as a
68-
comma-separated list of colors and attributes:
65+
The plugin can also be configured to show when copy or synchronized panes mode
66+
is active. If enabled, the `#{prefix_highlight}` token will be replaced with
67+
the string `Copy` when copy mode is enabled and `Sync` for synchronized panes.
68+
The style for copy and sync mode can be configured as a comma-separated list of
69+
colors and attributes:
6970

7071
```tmux.conf
7172
set -g @prefix_highlight_show_copy_mode 'on'
7273
set -g @prefix_highlight_copy_mode_attr 'fg=black,bg=yellow,bold' # default is 'fg=default,bg=yellow'
74+
set -g @prefix_highlight_show_sync_mode 'on'
75+
set -g @prefix_highlight_sync_mode_attr 'fg=black,bg=green' # default is 'fg=default,bg=yellow'
7376
```
7477

75-
The `prefix` prompt and `copy` prompt can also be configured:
78+
The `prefix`, `copy` and `sync` prompts can also be configured:
7679

7780
```tmux.conf
7881
set -g @prefix_highlight_prefix_prompt 'Wait'
7982
set -g @prefix_highlight_copy_prompt 'Copy'
83+
set -g @prefix_highlight_sync_prompt 'Sync'
8084
```
8185

8286
Additionally, the plugin can be configured to attach optional affixes to the

prefix_highlight.tmux

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ bg_color_config='@prefix_highlight_bg'
1111
output_prefix='@prefix_highlight_output_prefix'
1212
output_suffix='@prefix_highlight_output_suffix'
1313
show_copy_config='@prefix_highlight_show_copy_mode'
14+
show_sync_config='@prefix_highlight_show_sync_mode'
1415
copy_attr_config='@prefix_highlight_copy_mode_attr'
16+
sync_attr_config='@prefix_highlight_sync_attr'
1517
prefix_prompt='@prefix_highlight_prefix_prompt'
1618
copy_prompt='@prefix_highlight_copy_prompt'
19+
sync_prompt='@prefix_highlight_sync_prompt'
1720
empty_prompt='@prefix_highlight_empty_prompt'
1821
empty_attr_config='@prefix_highlight_empty_attr'
1922
empty_has_affixes='@prefix_highlight_empty_has_affixes'
@@ -22,7 +25,7 @@ tmux_option() {
2225
local -r value=$(tmux show-option -gqv "$1")
2326
local -r default="$2"
2427

25-
if [ ! -z "$value" ]; then
28+
if [ -n "$value" ]; then
2629
echo "$value"
2730
else
2831
echo "$default"
@@ -33,9 +36,11 @@ tmux_option() {
3336
default_fg='colour231'
3437
default_bg='colour04'
3538
default_copy_attr='fg=default,bg=yellow'
39+
default_sync_attr='fg=default,bg=yellow'
3640
default_empty_attr='fg=default,bg=default'
3741
default_prefix_prompt=$(tmux_option prefix | tr "[:lower:]" "[:upper:]" | sed 's/C-/\^/')
3842
default_copy_prompt='Copy'
43+
default_sync_prompt='Sync'
3944
default_empty_prompt=''
4045

4146
highlight() {
@@ -44,15 +49,19 @@ highlight() {
4449
prefix="$2" \
4550
prefix_highlight="$3" \
4651
show_copy_mode="$4" \
47-
copy_highlight="$5" \
48-
output_prefix="$6" \
49-
output_suffix="$7" \
50-
copy="$8" \
51-
empty="$9"
52+
show_sync_mode="$5" \
53+
copy_highlight="$6" \
54+
sync_highlight="$7" \
55+
output_prefix="$8" \
56+
output_suffix="$9" \
57+
copy="${10}" \
58+
sync="${11}" \
59+
empty="${12}"
5260

5361
local -r status_value="$(tmux_option "$status")"
5462
local -r prefix_with_optional_affixes="$output_prefix$prefix$output_suffix"
5563
local -r copy_with_optional_affixes="$output_prefix$copy$output_suffix"
64+
local -r sync_with_optional_affixes="$output_prefix$sync$output_suffix"
5665

5766
if [[ "on" = "$empty_has_affixes" ]]; then
5867
local -r empty_with_optional_affixes="$output_prefix$empty$output_suffix"
@@ -61,12 +70,17 @@ highlight() {
6170
fi
6271

6372
if [[ "on" = "$show_copy_mode" ]]; then
64-
local -r fallback="${copy_highlight}#{?pane_in_mode,$copy_with_optional_affixes,${empty_highlight}$empty_with_optional_affixes}"
65-
else
66-
local -r fallback="${empty_highlight}$empty_with_optional_affixes"
73+
local -r copy_mode="${copy_highlight}#{?pane_in_mode,$copy_with_optional_affixes,}"
74+
fi
75+
76+
if [[ "on" = "$show_sync_mode" ]]; then
77+
local -r sync_panes="${sync_highlight}#{?synchronize-panes,$sync_with_optional_affixes,}"
6778
fi
6879

69-
local -r highlight_on_prefix="${prefix_highlight}#{?client_prefix,$prefix_with_optional_affixes,$fallback}#[default]"
80+
local -r extended_highlights="${copy_mode}${sync_panes}"
81+
local -r client_prefix="#{?client_prefix,$prefix_with_optional_affixes,$empty_with_optional_affixes}"
82+
83+
local -r highlight_on_prefix="${prefix_highlight}${client_prefix}${extended_highlights}#[default]"
7084
tmux set-option -gq "$status" "${status_value/$place_holder/$highlight_on_prefix}"
7185
}
7286

@@ -75,28 +89,35 @@ main() {
7589
fg_color=$(tmux_option "$fg_color_config" "$default_fg") \
7690
bg_color=$(tmux_option "$bg_color_config" "$default_bg") \
7791
show_copy_mode=$(tmux_option "$show_copy_config" "off") \
92+
show_sync_mode=$(tmux_option "$show_sync_config" "off") \
7893
output_prefix=$(tmux_option "$output_prefix" " ") \
7994
output_suffix=$(tmux_option "$output_suffix" " ") \
8095
copy_attr=$(tmux_option "$copy_attr_config" "$default_copy_attr") \
96+
sync_attr=$(tmux_option "$sync_attr_config" "$default_sync_attr") \
8197
prefix_prompt=$(tmux_option "$prefix_prompt" "$default_prefix_prompt") \
8298
copy_prompt=$(tmux_option "$copy_prompt" "$default_copy_prompt") \
99+
sync_prompt=$(tmux_option "$sync_prompt" "$default_sync_prompt") \
83100
empty_prompt=$(tmux_option "$empty_prompt" "$default_empty_prompt") \
84101
empty_attr=$(tmux_option "$empty_attr_config" "$default_empty_attr") \
85102
empty_has_affixes=$(tmux_option "$empty_has_affixes" "off")
86103

87104
local -r \
88105
prefix_highlight="#[fg=$fg_color,bg=$bg_color]" \
89106
copy_highlight="${copy_attr:+#[default,$copy_attr]}" \
107+
sync_highlight="${sync_attr:+#[default,$sync_attr]}" \
90108
empty_highlight="${empty_attr:+#[default,$empty_attr]}"
91109

92110
highlight "status-right" \
93111
"$prefix_prompt" \
94112
"$prefix_highlight" \
95113
"$show_copy_mode" \
114+
"$show_sync_mode" \
96115
"$copy_highlight" \
116+
"$sync_highlight" \
97117
"$output_prefix" \
98118
"$output_suffix" \
99119
"$copy_prompt" \
120+
"$sync_prompt" \
100121
"$empty_prompt" \
101122
"$empty_highlight" \
102123
"$empty_has_affixes"
@@ -105,10 +126,13 @@ main() {
105126
"$prefix_prompt" \
106127
"$prefix_highlight" \
107128
"$show_copy_mode" \
129+
"$show_sync_mode" \
108130
"$copy_highlight" \
131+
"$sync_highlight" \
109132
"$output_prefix" \
110133
"$output_suffix" \
111134
"$copy_prompt" \
135+
"$sync_prompt" \
112136
"$empty_prompt" \
113137
"$empty_highlight" \
114138
"$empty_has_affixes"

0 commit comments

Comments
 (0)