Skip to content

Commit 8880f9c

Browse files
piutranqerickpintor
authored andcommitted
Add support empty prompt (for issue tmux-plugins#14) (tmux-plugins#17)
* When prefix is off, empty prompt is shown and it can be configurable. * List of new configures: @prefix_highlight_prompt - set prompt when prefix is off. default is '' (empty char) @prefix_highlight_empty_attr - set attribute of empty prompt. default is 'fg=default,bg=default' @prefix_highlight_empty_has_affixes - set empty prompt can be attached optional affixes. default is 'off' * Descriptions and examples are written on README.md
1 parent 61e8293 commit 8880f9c

File tree

2 files changed

+47
-7
lines changed

2 files changed

+47
-7
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,24 @@ set -g @prefix_highlight_output_prefix '< '
8888
set -g @prefix_highlight_output_suffix ' >'
8989
```
9090

91+
The empty (shown when prefix is off) prompt and attribute can be configured,
92+
It is useful for aligning segments.
93+
94+
```tmux.conf
95+
set -g @prefix_highlight_empty_prompt ' ' # default is '' (empty char)
96+
set -g @prefix_highlight_empty_attr 'fg=default,bg=green' # default is 'fg=default,bg=default'
97+
```
98+
99+
Defaultly, empty prompt can't be attached optional affixes.
100+
If you want attach affixes on empty prompt, config `@prefix_highlight_empty_has_affixes` to `on`.
101+
102+
```tmux.conf
103+
set -g @prefix_highlight_empty_has_affixes 'on' # default is 'off'
104+
set -g @prefix_highlight_empty_prompt 'Tmux'
105+
set -g @prefix_highlight_output_prefix '< '
106+
set -g @prefix_highlight_output_suffix ' >'
107+
```
108+
91109
### License
92110

93111
[MIT](LICENSE)

prefix_highlight.tmux

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ show_copy_config='@prefix_highlight_show_copy_mode'
1414
copy_attr_config='@prefix_highlight_copy_mode_attr'
1515
prefix_prompt='@prefix_highlight_prefix_prompt'
1616
copy_prompt='@prefix_highlight_copy_prompt'
17+
empty_prompt='@prefix_highlight_empty_prompt'
18+
empty_attr_config='@prefix_highlight_empty_attr'
19+
empty_has_affixes='@prefix_highlight_empty_has_affixes'
1720

1821
tmux_option() {
1922
local -r value=$(tmux show-option -gqv "$1")
@@ -30,8 +33,10 @@ tmux_option() {
3033
default_fg='colour231'
3134
default_bg='colour04'
3235
default_copy_attr='fg=default,bg=yellow'
36+
default_empty_attr='fg=default,bg=default'
3337
default_prefix_prompt=$(tmux_option prefix | tr "[:lower:]" "[:upper:]" | sed 's/C-/\^/')
3438
default_copy_prompt='Copy'
39+
default_empty_prompt=''
3540

3641
highlight() {
3742
local -r \
@@ -42,16 +47,23 @@ highlight() {
4247
copy_highlight="$5" \
4348
output_prefix="$6" \
4449
output_suffix="$7" \
45-
copy="$8"
50+
copy="$8" \
51+
empty="$9"
4652

4753
local -r status_value="$(tmux_option "$status")"
4854
local -r prefix_with_optional_affixes="$output_prefix$prefix$output_suffix"
4955
local -r copy_with_optional_affixes="$output_prefix$copy$output_suffix"
5056

57+
if [[ "on" = "$empty_has_affixes" ]]; then
58+
local -r empty_with_optional_affixes="$output_prefix$empty$output_suffix"
59+
else
60+
local -r empty_with_optional_affixes="$empty"
61+
fi
62+
5163
if [[ "on" = "$show_copy_mode" ]]; then
52-
local -r fallback="${copy_highlight}#{?pane_in_mode,$copy_with_optional_affixes,}"
64+
local -r fallback="${copy_highlight}#{?pane_in_mode,$copy_with_optional_affixes,${empty_highlight}$empty_with_optional_affixes}"
5365
else
54-
local -r fallback=""
66+
local -r fallback="${empty_highlight}$empty_with_optional_affixes"
5567
fi
5668

5769
local -r highlight_on_prefix="${prefix_highlight}#{?client_prefix,$prefix_with_optional_affixes,$fallback}#[default]"
@@ -67,11 +79,15 @@ main() {
6779
output_suffix=$(tmux_option "$output_suffix" " ") \
6880
copy_attr=$(tmux_option "$copy_attr_config" "$default_copy_attr") \
6981
prefix_prompt=$(tmux_option "$prefix_prompt" "$default_prefix_prompt") \
70-
copy_prompt=$(tmux_option "$copy_prompt" "$default_copy_prompt")
82+
copy_prompt=$(tmux_option "$copy_prompt" "$default_copy_prompt") \
83+
empty_prompt=$(tmux_option "$empty_prompt" "$default_empty_prompt") \
84+
empty_attr=$(tmux_option "$empty_attr_config" "$default_empty_attr") \
85+
empty_has_affixes=$(tmux_option "$empty_has_affixes" "off")
7186

7287
local -r \
7388
prefix_highlight="#[fg=$fg_color,bg=$bg_color]" \
74-
copy_highlight="${copy_attr:+#[default,$copy_attr]}"
89+
copy_highlight="${copy_attr:+#[default,$copy_attr]}" \
90+
empty_highlight="${empty_attr:+#[default,$empty_attr]}"
7591

7692
highlight "status-right" \
7793
"$prefix_prompt" \
@@ -80,7 +96,10 @@ main() {
8096
"$copy_highlight" \
8197
"$output_prefix" \
8298
"$output_suffix" \
83-
"$copy_prompt"
99+
"$copy_prompt" \
100+
"$empty_prompt" \
101+
"$empty_highlight" \
102+
"$empty_has_affixes"
84103

85104
highlight "status-left" \
86105
"$prefix_prompt" \
@@ -89,7 +108,10 @@ main() {
89108
"$copy_highlight" \
90109
"$output_prefix" \
91110
"$output_suffix" \
92-
"$copy_prompt"
111+
"$copy_prompt" \
112+
"$empty_prompt" \
113+
"$empty_highlight" \
114+
"$empty_has_affixes"
93115
}
94116

95117
main

0 commit comments

Comments
 (0)