Skip to content

Commit a53ea59

Browse files
committed
initial commit
0 parents  commit a53ea59

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Munif Tanjim
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

mode_indicator.tmux

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
mode_indicator_placeholder="\#{tmux_mode_indicator}"
6+
7+
prefix_prompt_config='@mode_indicator_prefix_prompt'
8+
copy_prompt_config='@mode_indicator_copy_prompt'
9+
sync_prompt_config='@mode_indicator_sync_prompt'
10+
empty_prompt_config='@mode_indicator_empty_prompt'
11+
prefix_mode_style_config='@mode_indicator_prefix_mode_style'
12+
copy_mode_style_config='@mode_indicator_copy_mode_style'
13+
sync_mode_style_config='@mode_indicator_sync_mode_style'
14+
empty_mode_style_config='@mode_indicator_empty_mode_style'
15+
16+
tmux_option() {
17+
local -r option=$(tmux show-option -gqv "$1")
18+
local -r fallback="$2"
19+
echo "${option:-$fallback}"
20+
}
21+
22+
indicator_style() {
23+
local -r style=$(tmux_option "$1" "$2")
24+
echo "${style:+#[${style/,/]#[}]}"
25+
}
26+
27+
init_tmux_mode_indicator() {
28+
local -r \
29+
prefix_prompt=$(tmux_option "$prefix_prompt_config" " WAIT ") \
30+
copy_prompt=$(tmux_option "$copy_prompt_config" " COPY ") \
31+
sync_prompt=$(tmux_option "$sync_prompt_config" " SYNC ") \
32+
empty_prompt=$(tmux_option "$empty_prompt_config" " TMUX ") \
33+
prefix_style=$(indicator_style "$prefix_mode_style_config" "bg=blue,fg=black") \
34+
copy_style=$(indicator_style "$copy_mode_style_config" "bg=yellow,fg=black") \
35+
sync_style=$(indicator_style "$sync_mode_style_config" "bg=red,fg=black") \
36+
empty_style=$(indicator_style "$empty_mode_style_config" "bg=cyan,fg=black")
37+
38+
local -r \
39+
mode_prompt="#{?client_prefix,$prefix_prompt,#{?pane_in_mode,$copy_prompt,#{?pane_synchronized,$sync_prompt,$empty_prompt}}}" \
40+
mode_style="#{?client_prefix,$prefix_style,#{?pane_in_mode,$copy_style,#{?pane_synchronized,$sync_style,$empty_style}}}"
41+
42+
local -r mode_indicator="#[default]$mode_style$mode_prompt#[default]"
43+
44+
local -r status_left_value="$(tmux_option "status-left")"
45+
tmux set-option -gq "status-left" "${status_left_value/$mode_indicator_placeholder/$mode_indicator}"
46+
47+
local -r status_right_value="$(tmux_option "status-right")"
48+
tmux set-option -gq "status-right" "${status_right_value/$mode_indicator_placeholder/$mode_indicator}"
49+
}
50+
51+
init_tmux_mode_indicator

0 commit comments

Comments
 (0)