forked from hiroppy/tmux-agent-sidebar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent-sidebar.conf
More file actions
71 lines (64 loc) · 4.91 KB
/
Copy pathagent-sidebar.conf
File metadata and controls
71 lines (64 loc) · 4.91 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
63
64
65
66
67
68
69
70
71
# tmux-agent-sidebar plugin
# Load via the entry point script:
# run-shell /path/to/tmux-agent-sidebar.tmux
#
# Customizable options (set BEFORE loading to override):
# @sidebar_width - sidebar width in columns, or percentage of window width (default: 15%)
# @sidebar_position - sidebar placement: left or right (default: left)
# @sidebar_bottom_height - bottom panel height in lines (default: 20, 0 to hide)
# @sidebar_auto_create - create sidebar automatically for new windows (default: on)
# @sidebar_auto_create_delay - seconds to defer auto-create after a new window is
# created so a declaratively-built window (e.g.
# tmuxinator's split-window + select-layout) finishes
# first; accepts fractional seconds (default: 0)
# @sidebar_pet - show pet animation in bottom panel (default: off)
# @sidebar_key - keybinding to toggle sidebar (default: e)
# @sidebar_key_all - keybinding to toggle sidebar in all windows (default: E)
# @sidebar_color_* - 256-color codes or #RRGGBB hex colors for sidebar elements
#
# Internal tmux options used by the plugin:
# @agent_sidebar_dir - plugin directory (auto-detected by tmux-agent-sidebar.tmux)
# @sidebar_pid - pane option used to notify running sidebar instances
# --- Plugin location ---
# @agent_sidebar_dir must be set by tmux-agent-sidebar.tmux before sourcing this file
# --- Sidebar options ---
# Colors are managed in Rust (src/ui/colors.rs). Users may override any
# @sidebar_color_* tmux option in their own config. Non-color sidebar
# options are seeded here only when unset.
if -F '#{==:#{@sidebar_width},}' 'set -g @sidebar_width 15%'
if -F '#{==:#{@sidebar_position},}' 'set -g @sidebar_position left'
if -F '#{==:#{@sidebar_bottom_height},}' 'set -g @sidebar_bottom_height 20'
if -F '#{==:#{@sidebar_auto_create},}' 'set -g @sidebar_auto_create on'
if -F '#{==:#{@sidebar_auto_create_delay},}' 'set -g @sidebar_auto_create_delay 0'
if -F '#{==:#{@sidebar_pet},}' 'set -g @sidebar_pet off'
if -F '#{==:#{@sidebar_key},}' 'set -g @sidebar_key e'
if -F '#{==:#{@sidebar_key_all},}' 'set -g @sidebar_key_all E'
# --- Keybindings ---
run-shell 'key="$(tmux display-message -p "#{@sidebar_key}")"; bin="$(tmux display-message -p "#{@agent_sidebar_bin}")"; tmux bind "$key" run-shell "\"$bin\" toggle \"##{window_id}\" \"##{pane_current_path}\""'
run-shell 'key="$(tmux display-message -p "#{@sidebar_key_all}")"; bin="$(tmux display-message -p "#{@agent_sidebar_bin}")"; tmux bind "$key" run-shell "\"$bin\" toggle-all"'
# --- Hooks (remove our own entries first to prevent duplicates on config reload) ---
run-shell 'tmux show-hooks -g after-new-window | awk "/@agent_sidebar_bin/ && /toggle --create-only/ { print \$1 }" | xargs -rn1 tmux set-hook -gu'
run-shell 'tmux show-hooks -g after-select-pane | awk "/@sidebar_pid/ && /kill -USR1/ { print \$1 }" | xargs -rn1 tmux set-hook -gu'
run-shell 'tmux show-hooks -g after-select-window | awk "/@sidebar_pid/ && /kill -USR1/ { print \$1 }" | xargs -rn1 tmux set-hook -gu'
run-shell 'tmux show-hooks -g pane-exited | awk "/@agent_sidebar_bin/ && /auto-close/ { print \$1 }" | xargs -rn1 tmux set-hook -gu'
# --- Auto sidebar on new window (create-only, no toggle) ---
# With @sidebar_auto_create_delay non-zero, defer the create-only split into a
# backgrounded shell that sleeps first. This lets a window built declaratively
# (e.g. tmuxinator's split-window + select-layout sequence) finish before the
# sidebar pane is injected — otherwise the sidebar lands while the window still
# has one pane and the later select-layout is computed with an extra pane,
# scrambling pane sizes and roles. The sync/deferred choice is fixed at load
# time; the duration itself is read at fire time. Switching the delay between
# zero and non-zero needs a config reload to re-pick the hook.
if -F '#{!=:#{@sidebar_auto_create},off}' {
if -F '#{==:#{@sidebar_auto_create_delay},0}' {
set-hook -ga after-new-window 'run-shell "\"#{@agent_sidebar_bin}\" toggle --create-only \"#{window_id}\" \"#{pane_current_path}\""'
} {
set-hook -ga after-new-window 'run-shell -b "sleep \"#{@sidebar_auto_create_delay}\"; \"#{@agent_sidebar_bin}\" toggle --create-only \"#{window_id}\" \"#{pane_current_path}\""'
}
}
# --- Notify sidebar on pane/window focus change (SIGUSR1 → instant refresh) ---
set-hook -ga after-select-pane "run-shell -b 'tmux list-panes -t \"#{window_id}\" -F \"#{@sidebar_pid}\" 2>/dev/null | while read pid; do [ -n \"\$pid\" ] && kill -USR1 \"\$pid\" 2>/dev/null; done; true'"
set-hook -ga after-select-window "run-shell -b 'tmux list-panes -t \"#{window_id}\" -F \"#{@sidebar_pid}\" 2>/dev/null | while read pid; do [ -n \"\$pid\" ] && kill -USR1 \"\$pid\" 2>/dev/null; done; true'"
# --- Auto close window when only sidebar remains ---
set-hook -ga pane-exited 'run-shell "\"#{@agent_sidebar_bin}\" auto-close \"#{window_id}\""'