-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathagent-indicator.tmux
More file actions
executable file
·62 lines (53 loc) · 2.07 KB
/
agent-indicator.tmux
File metadata and controls
executable file
·62 lines (53 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env bash
# tmux-agent-indicator bootstrap.
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
do_interpolation() {
local string="$1"
string="${string//\#\{agent_indicator\}/#($CURRENT_DIR/scripts/indicator.sh)}"
string="${string//\#\{agent_session_dots\}/#($CURRENT_DIR/scripts/session-dots.sh '#S')}"
echo "$string"
}
update_tmux_option() {
local option="$1"
local option_value
option_value=$(tmux show-option -gqv "$option")
if [ -z "$option_value" ]; then
return
fi
tmux set-option -gq "$option" "$(do_interpolation "$option_value")"
}
register_hook_once() {
local hook_type="$1"
local command="$2"
local match="${3:-$CURRENT_DIR}"
local existing_hooks
existing_hooks=$(tmux show-hooks -g "$hook_type" 2>/dev/null || true)
# Remove all previously registered plugin hooks to avoid duplicates.
while IFS= read -r line; do
[ -z "$line" ] && continue
local existing_name
existing_name="${line%% *}"
tmux set-hook -gu "$existing_name" 2>/dev/null || true
done < <(printf '%s\n' "$existing_hooks" | grep -F "$match" || true)
tmux set-hook -ag "$hook_type" "$command"
}
register_focus_hooks() {
local hook_script="$CURRENT_DIR/scripts/pane-focus-in.sh"
local hook_command="run-shell \"$hook_script \\\"#{pane_id}\\\" \\\"#{window_id}\\\"\""
register_hook_once "pane-focus-in" "$hook_command"
register_hook_once "after-select-window" "$hook_command"
register_hook_once "after-select-pane" "$hook_command"
}
main() {
tmux set-environment -g TMUX_AGENT_INDICATOR_DIR "$CURRENT_DIR"
update_tmux_option "status-right"
update_tmux_option "status-left"
update_tmux_option "@minimal-tmux-status-right"
update_tmux_option "@minimal-tmux-status-left"
update_tmux_option "@minimal-tmux-status-right-extra"
update_tmux_option "@minimal-tmux-status-left-extra"
register_focus_hooks
local session_script="$CURRENT_DIR/scripts/session-changed.sh"
register_hook_once "client-session-changed" "run-shell \"$session_script\""
}
main