Skip to content

Commit d9e4e60

Browse files
authored
New setting options_scope which allows having per session configuration (tmux-plugins#31)
* use set-prefix on per sesion basis * allow setting option scope
1 parent 3e9cfc0 commit d9e4e60

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,16 @@ set -g @prefix_highlight_output_prefix '< '
116116
set -g @prefix_highlight_output_suffix ' >'
117117
```
118118

119+
#### Change option scope (default g - global)
120+
121+
Follows same rules as `set-option`
122+
123+
**Special case**: To set scope to session use `'-'`, because by default session scope used when no param is provided.
124+
125+
```tmux.conf
126+
set -g @prefix_highlight_option_scope '-'
127+
```
128+
119129
### License
120130

121131
[MIT](LICENSE)

prefix_highlight.tmux

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ set -e
66
place_holder="\#{prefix_highlight}"
77

88
# Possible configurations
9+
option_scope_config='@prefix_highlight_option_scope'
910
fg_color_config='@prefix_highlight_fg'
1011
bg_color_config='@prefix_highlight_bg'
1112
output_prefix='@prefix_highlight_output_prefix'
@@ -22,7 +23,7 @@ empty_attr_config='@prefix_highlight_empty_attr'
2223
empty_has_affixes='@prefix_highlight_empty_has_affixes'
2324

2425
tmux_option() {
25-
local -r value=$(tmux show-option -gqv "$1")
26+
local -r value=$(tmux show-option -Aqv "$1")
2627
local -r default="$2"
2728

2829
if [ -n "$value" ]; then
@@ -36,6 +37,14 @@ format_style() {
3637
echo "#[${1}]" | sed -e 's/,/]#[/g'
3738
}
3839

40+
interpolate() {
41+
local -r option=$1
42+
local -r replacement=$2
43+
local -r option_scope=${3#-}
44+
local -r option_value=$(tmux_option "$option")
45+
tmux set-option -"$option_scope"q "$option" "${option_value/$place_holder/$replacement}"
46+
}
47+
3948
# Defaults
4049
default_fg='colour231'
4150
default_bg='colour04'
@@ -49,6 +58,7 @@ default_empty_prompt=''
4958

5059
main() {
5160
local -r \
61+
option_scope=$(tmux_option "$option_scope_config" "g") \
5262
fg_color=$(tmux_option "$fg_color_config" "$default_fg") \
5363
bg_color=$(tmux_option "$bg_color_config" "$default_bg") \
5464
show_copy_mode=$(tmux_option "$show_copy_config" "off") \
@@ -94,11 +104,9 @@ main() {
94104

95105
local -r highlight="#{?client_prefix,$prefix_mode,$fallback}#[default]"
96106

97-
local -r status_left_value="$(tmux_option "status-left")"
98-
tmux set-option -gq "status-left" "${status_left_value/$place_holder/$highlight}"
107+
interpolate "status-left" "$highlight" "$option_scope"
99108

100-
local -r status_right_value="$(tmux_option "status-right")"
101-
tmux set-option -gq "status-right" "${status_right_value/$place_holder/$highlight}"
109+
interpolate "status-right" "$highlight" "$option_scope"
102110
}
103111

104112
main

0 commit comments

Comments
 (0)