-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtmux.conf
328 lines (279 loc) · 22.2 KB
/
tmux.conf
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# ==========================
# === General Settings ===
# ==========================
### Global Options ###
set-option -sg default-terminal "screen-256color" # default terminal for new windows; must be 'screen', 'tmux' or derivative
set-option -sa terminal-features[0] ":RGB" # add support for RGB-colour w/ SGR escape-sequences to 'xterm*' (index 0)
set-option -g focus-events on # pass-through requested focus-events to applications running inside tmux (e.g. autoread option in Vim)
set-option -g mouse on # captures & allows mouse events to be bound as key bindings
set-option -g base-index 1 # index to start numbering new windows; matches numbers layout on keyboards
set-option -g history-limit 50000 # maximum number of lines held in window history
set-option -g display-time 1500 # time in ms status line messages are displayed
set-option -g repeat-time 500 # time in ms multiple commands can be entered w/o the prefix-key
set-option -sg escape-time 100 # time in ms tmux waits after an escape is input
set-option -g set-titles on # sets client terminal title using 'tsl' & 'fsl' terminfo(5)
set-option -g status on # show status w/ height of 1 row (default); see own section
set-option -g status-interval 5 # time in sec that status line gets updated
# set-option -g status-keys vi # vi or emacs (default) style key bindings in the status line
# set-option -g renumber-windows on # auto-renumber other windows in numerical order when a window closes
### Window Options ###
set-option -wg clock-mode-colour "colour166" # same as color_main / color_orange
set-option -wg automatic-rename off # when 'on', sets window name using automatic-rename-format
# set-option -wg automatic-rename-format # FORMAT used for automatic-rename when enabled
# ==========================
# === Key Bindings ===
# ==========================
### Prefix Adjustment ###
set-option -g prefix2 C-a # use C-a as a secondary prefix
bind-key C-a send-prefix -2 # sends secondary prefix to window
### Unbind Defaults ###
unbind-key '$' # rename-session
unbind-key , # rename-window
unbind-key "#" # list-buffer
unbind-key = # choose-buffer
unbind-key & # kill-window
unbind-key % # split-window -h
unbind-key '"' # split-window
unbind-key [ # copy-mode
unbind-key ] # paste-buffer
unbind-key '{' # swap-pane -U
unbind-key '}' # swap-pane -D
unbind-key n # next-window
unbind-key p # previous-window
unbind-key r # refresh-client
unbind-key : # command-prompt
unbind-key ';' # last-pane
unbind-key C-o # rotate-window
# unbind-key -a # remove all key bindings
### General Conveniences ###
bind-key C-e new-window -n "tmux.conf" \
"sh -c '\${EDITOR:-nvim} ~/.tmux.conf && tmux source-file ~/.tmux.conf && tmux display \"Edited config reloaded\"'" # Edit config & reload
bind-key C-r source-file ~/.tmux.conf \; display-message "Config reloaded" # Reload tmux config
bind-key ? list-keys # List all key bindings; not just from the default prefix & root keytables (-N option)
bind-key / customize-mode # Browse (& modify) options & key-bindings from a list interactively
bind-key ";" command-prompt -p "→" # Activate command-prompt using ";" instead of ":", just like in Neovim config
bind-key -T root C-c if-shell -F "#{m/r:(buffer|client|tree|options)-mode,#{pane_mode}}" "send-keys q" "send-keys C-c" # Also allow C-c to exit choose & options modes; copy, view & clock modes already exits on C-c
### Session Management ###
bind-key S command-prompt -p "New session w/ name:" "new-session -c $HOME -s '%%'" # Create a new named session
bind-key R command-prompt -p "Rename current session:" "rename-session '%%'" # Manually rename session
### Window Management ###
bind-key c new-window -c "#{pane_current_path}" # Create new window w/ CWD of current pane
bind-key C new-window -c "#{pane_current_path}" -a # Same as prefix-c, but new window will have index of (curr_win_index + 1)
bind-key n new-window -c "#{pane_current_path}" \; command-prompt -I "#{window_name}"\
-p "New window w/ name:" "rename-window '%%'" # Same as prefix-c, then immediately prompt for new name
bind-key X new-window -c "#{pane_current_path}" "/opt/homebrew/bin/xonsh" # Same as prefix-c, but using the Xonsh shell
bind-key N move-window -r # Renumber windows starting w/ base-index
bind-key r command-prompt -I "#{window_name}"\
-p "Rename current window:" "rename-window '%%'" # Manually rename window
bind-key % command-prompt -p "Swap w/ window:" "swap-window -d -t '%%'" # Swap 2 windows while keeping the current view
bind-key $ command-prompt -p "Move current window to:" "move-window -b -t '%%'" # Move active window to new index # TODO: when moving window to new index, conditionally apply -a/-b flag, based on whether the target index already exists
# bind-key ^ command-prompt -p "Link window from (session:window):" \
# "link-window -s %% -a" # Link current window after destination-window # TODO: find use cases for link-window; see https://samm81.github.io/tmux-link-window/
bind-key -r a last-window # TODO: create last-N-windows plugin & use for that
bind-key -r [ previous-window
bind-key -r ] next-window
bind-key -r "{" swap-window -d -t -1 # Moves current window one position to the left
bind-key -r "}" swap-window -d -t +1 # Moves current window one position to the right
### Copy Mode (see own section) ###
bind-key C-c copy-mode # Enter copy mode
bind-key p paste-buffer -p # Insert contents of paste buffer into current pane
bind-key '"' choose-buffer -Z # Interactively choose buffer from list
bind-key = list-buffers # List paste buffers
# ==========================
# === Copy Mode ===
# ==========================
### Options ###
set-option -wg mode-keys vi # Use vi style key bindings in copy mode
### Key (Un)Binds ###
unbind-key -T copy-mode-vi Space # begin-selection
unbind-key -T copy-mode-vi v # toggle-rectangle
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi y send-keys -X copy-selection-and-cancel
bind-key -T copy-mode-vi Y send-keys -X copy-end-of-line-and-cancel
bind-key -T copy-mode-vi C-y send-keys -X copy-line-and-cancel
bind-key -T copy-mode-vi Space send-keys -X rectangle-toggle
# ==========================
# === Theme Definition ===
# ==========================
### Color Variables ###
color_orange="colour166" # 208, 166
color_purple="colour134" # 135, 134
color_green="colour076" # 070
color_blue="colour33"
color_yellow="colour220"
color_red="colour160"
color_black="colour232"
color_white="white" # 015
### Color Components ###
color_dark="$color_black"
color_light="$color_white"
color_session_text="$color_blue"
color_status_text="colour245"
color_main="$color_orange" # NOTE: consider switching-up color_main, e.g. $color_green
color_secondary="$color_purple"
color_level_ok="$color_green"
color_level_warn="$color_yellow"
color_level_stress="$color_red"
color_window_off_status_bg="colour238"
color_window_off_status_current_bg="colour242"
### Special Symbols ###
separator_powerline_left=""
separator_powerline_right=""
# ==========================
# === Status Line ===
# ==========================
### Toggling Keybind ###
bind-key -T root -r S-F11 if-shell -F "#{s/off//:status}" "set-option -g status off" "set-option -g status on" # allow status line toggling when local client keybinds are disabled (see Nesting Sessions section)
bind-key -T disabled -r S-F11 if-shell -F "#{s/off//:status}" "set-option -g status off" "set-option -g status on" # NOTE: the 's/foo/bar/:' format conditional (-F) performs substitution, similar to sed's syntax
### General Appearance ###
set-option -g mode-style "fg=$color_light,bg=$color_main" # window modes style (copy, view, choose)
set-option -g status-position top # top or bottom (default)
set-option -g status-justify left # sets position of windows list in status line
set-option -g status-left-length 12 # max length of left component of status line: 10 for the session_name text, 2 for the separator-string ' ❱' (default: 10)
set-option -g status-right-length 100 # max length of right component of status line (default: 40)
set-option -g message-style "fg=$color_main,bg=$color_dark" # command-prompt & status line message
set-option -g status-style "fg=$color_status_text,bg=$color_dark" # status line style
### Session Name Truncation ###
session_name_max_len="#{e|-:#{status-left-length},2}" # NOTE: subtract 2 b/c the separator ' ❱' has length 2; TODO: dynamically determine the subtracted length given the sep-str
session_name_truncated="#{s/^(.#{a:123}$session_name_max_len#{a:125}).*/#{a:92}1/:session_name}" # ASCII replacements: #{a:92} == \, #{a:123} == {, #{a:125} == }
session_name_ellipsis="#{s/^(.#{a:123}#{e|-:$session_name_max_len,1}#{a:125}).*/#{a:92}1/:session_name}…" # subtract 1 for the length of the '…' symbol, and append it to the end of the expanded name-str
session_name_displayed="#{?#{==:#{session_name},$session_name_truncated},#{session_name},${session_name_ellipsis}}"
### Windows List ###
set-option -g window-status-separator "" # separator b/w windows in status line; default is " "
set-option -wg window-status-style "fg=$color_status_text,bg=$color_dark" # inactive windows status style
set-option -wg window-status-current-style "fg=$color_light,bold,bg=$color_main" # like window-status-style, but for active window
set-option -wg window-status-format " #I:#W " # display format of windows on status line; #I=window_index, #W=window_name
set-option -wg window-status-current-format \
"#[fg=$color_dark,bg=$color_main]$separator_powerline_right#[default] #I:#W ● #[fg=$color_main,bg=$color_dark]$separator_powerline_right#[default]"
### Config tmux-plugin-sysstat Opts ###
set-option -g @sysstat_cpu_color_low "$color_level_ok"
set-option -g @sysstat_cpu_color_medium "$color_level_warn"
set-option -g @sysstat_cpu_color_stress "$color_level_stress"
set-option -g @sysstat_mem_view_tmpl "Mem:#[fg=#{mem.color}]#{mem.pused}#[default]"
set-option -g @sysstat_mem_color_low "$color_level_ok"
set-option -g @sysstat_mem_color_medium "$color_level_warn"
set-option -g @sysstat_mem_color_stress "$color_level_stress"
set-option -g @sysstat_swap_view_tmpl "Swp:#[fg=#{swap.color}]#{swap.pused}#[default]"
set-option -g @sysstat_swap_color_low "$color_level_ok"
set-option -g @sysstat_swap_color_medium "$color_level_warn"
set-option -g @sysstat_swap_color_stress "$color_level_stress"
load_avg_1min='#(dc -e "2 k [0n]sa $(uptime | rev | cut -d" " -f3 | rev) $(nproc) / d 1 >a p")' # NOTE: see https://en.wikipedia.org/wiki/Load_(computing)
# the same metric as above can be computed using `bc` with: `$ echo "scale=2; l_avg_1min = $(uptime | rev | cut -d' ' -f3 | rev) / $(nproc); if (l_avg_1min < 1) print 0; l_avg_1min" | bc -l`
load_avg_color_heavy="#{?#{e|<:$load_avg_1min,2},$color_level_warn,$color_level_stress}" # colors for when job queue is >=1 and >=2 per core respectively
load_avg_color="#{?#{e|<:$load_avg_1min,1},$color_level_ok,$load_avg_color_heavy}" # text color of the 1min load average stat; TODO: make PR to add colors to sysstat_loadavg in samoshkin/tmux-plugin-sysstat
### Config tmux-battery 🔋Opts ###
set-option -g @batt_icon_status_charged "🔋"
set-option -g @batt_icon_status_charging "⚡"
set-option -g @batt_icon_status_unknown "⚠️" # unknown-status only seems to occur when battery is still charging at 99%, before reaching 100%
set-option -g @batt_icon_charge_tier8 "██"
set-option -g @batt_icon_charge_tier7 "▇▇"
set-option -g @batt_icon_charge_tier6 "▆▆"
set-option -g @batt_icon_charge_tier5 "▅▅"
set-option -g @batt_icon_charge_tier4 "▄▄"
set-option -g @batt_icon_charge_tier3 "▃▃"
set-option -g @batt_icon_charge_tier2 "▂▂"
set-option -g @batt_icon_charge_tier1 "▁▁"
set-option -g @batt_color_status_primary_charged "$color_green" # same color as color_level_ok
set-option -g @batt_color_status_primary_charging "$color_yellow" # same color as color_level_warn
set-option -g @batt_color_status_primary_unknown "$color_yellow" # same color as color_level_warn
set-option -g @batt_color_charge_primary_tier8 "$color_level_ok" # [95%-100%]
set-option -g @batt_color_charge_primary_tier7 "$color_level_ok" # [80%-95%)
set-option -g @batt_color_charge_primary_tier6 "$color_level_ok" # [65%-80%)
set-option -g @batt_color_charge_primary_tier5 "$color_level_warn" # [50%-65%)
set-option -g @batt_color_charge_primary_tier4 "$color_level_warn" # [35%-50%)
set-option -g @batt_color_charge_primary_tier3 "$color_level_warn" # [20%-35%)
set-option -g @batt_color_charge_primary_tier2 "$color_level_stress" # (5%-20%)
set-option -g @batt_color_charge_primary_tier1 "$color_level_stress" # [0%-5%]
battery_color_bg="#{?#{==:#{client_key_table},disabled},$color_window_off_status_bg,$color_dark}" # set background color for the battery widget based on current key-table
bp="#{battery_percentage}"
battery_pct_lt_100p_format="#{?#{m/r:^[0-9]#{a:37},$bp}, $bp, $bp}" # NOTE: #{a:XYZ} performs decimal ASCII replacement; #{a:37} == %
battery_pct_justified="#{?#{==:$bp,100#{a:37}},$bp,$battery_pct_lt_100p_format}"
### Config tmux-prefix-highlight Opts ###
set-option -g @prefix_highlight_prefix_prompt "Pend"
set-option -g @prefix_highlight_fg "$color_light,bold"
set-option -g @prefix_highlight_bg "$color_main"
set-option -g @prefix_highlight_show_copy_mode "on"
set-option -g @prefix_highlight_copy_prompt "Copy"
set-option -g @prefix_highlight_copy_mode_attr "fg=$color_light,bold,bg=$color_main"
# set-option -g @prefix_highlight_empty_prompt "tmux" # placeholder text when not in any modes; good for permanently aligned widgets
# set-option -g @prefix_highlight_empty_attr "fg=$color_dark,bg=$color_secondary"
# set-option -g @prefix_highlight_empty_has_affixes "on"
### Widget Definitions ###
widget_bracket_L="#[fg=$color_secondary]❱#[default]" # status-right starting separator/delimiter
widget_bracket_R="#[fg=$color_secondary] ❰#[default]" # status-right starting separator/delimiter
widget_session="#[fg=$color_session_text]$session_name_displayed#[default]" # formatted & max-length-constrained session-name
widget_bar_sep="#[fg=$color_secondary]|#[default]" # status-right widget components separator/delimiter
widget_dot_sep="#[fg=$color_secondary]•#[default]" # status-right sysstat widget subcomponents separator/delimiter
widget_date="#[fg=$color_session_text]%a %b %d#[default]" # day-of-week, mon (3-char abbreviation) day-of-month [01-31]
widget_time="#[fg=$color_session_text]%H:%M#[default]" # hr:min (in 24-hr format); NOTE: see `$ man -3 strftime`
# widget_user="#[fg=$color_secondary]#(id -un)#[default]" # user id
# widget_user_host="#[fg=$color_secondary]#(whoami)#[default]@#h" # #h=host_short (no domain)
widget_load_avg_1min="1m:#[fg=$load_avg_color]$load_avg_1min#[default]" # load average over 1min only; instead of 1,5,15 mins as in #{sysstat_loadavg}
widget_sysstat="#{sysstat_cpu} $widget_dot_sep #{sysstat_mem} $widget_dot_sep #{sysstat_swap} $widget_dot_sep $widget_load_avg_1min" # TODO: review calcs (esp. for Apple Silicon CPU) & check issues & review lapsed PRs on GitHub
widget_battery="#{battery_color_fg}#[bg=$battery_color_bg]#{battery_icon}$battery_pct_justified#[default]" # provided by tmux-plugins/tmux-battery
widget_prefix_hl="#{prefix_highlight}" # provided by tmux-plugins/tmux-prefix-highlight
### Status Composition ###
set-option -g status-left "$widget_session $widget_bracket_L" # display string to left of status line
status_R_shared="$widget_bracket_R $widget_sysstat $widget_bar_sep $widget_battery $widget_bar_sep $widget_date" # static segments of the right status line
status_R_dynamic="#{?#{||:#{client_prefix},#{pane_in_mode}},$widget_prefix_hl, $widget_time}" # conditionally swap the end of the right status text, to produce the illusion that the highlighting is overlayed on top of the time
set-option -g status-right "$status_R_shared$status_R_dynamic#[default]" # display string to right of status line
# ==========================
# === Nesting Sessions ===
# ==========================
# Turn off all key-bindings & prefix handling on local session, so all keys are passed to inner/remote
# session. See - https://github.com/tmux/tmux/issues/237 (toggle on/off all keybindings #237)
# Also change status line/windows visual styles to indicate local Tmux handling has been disabled.
### Toggle Local Tmux Off ###
bind-key -T root S-F12 \
set-option prefix None \;\
set-option prefix2 None \;\
set-option key-table disabled \;\
set-option status-style "fg=$color_status_text,bg=$color_window_off_status_bg" \;\
set-option window-status-current-style "fg=$color_dark,bold,bg=$color_window_off_status_current_bg" \;\
set-option window-status-current-format "#[fg=$color_window_off_status_bg,bg=$color_window_off_status_current_bg]$separator_powerline_right#[default] #I:#W ○ #[fg=$color_window_off_status_current_bg,bg=$color_window_off_status_bg]$separator_powerline_right#[default]" \;\
set-option -g window-status-style "fg=$color_dark,bg=$color_window_off_status_bg" \;\
if-shell -F "#{pane_in_mode}" "send-keys -X cancel" \;\
refresh-client -S
### Toggle Local Tmux On ###
bind-key -T disabled S-F12 \
set-option -u prefix \;\
set-option -u prefix2 \;\
set-option -u key-table \;\
set-option -u status-style \;\
set-option -u window-status-current-style \;\
set-option -u window-status-current-format \;\
set-option -ug window-status-style \;\
refresh-client -S
# ==========================
# === Plugins ===
# ==========================
# NOTE: plugins live in ~/.tmux/plugins/ ;see list of plugins: https://github.com/tmux-plugins/list
set-option -g @plugin "tmux-plugins/tpm" # Tmux Plugin Manager
### Session Persistence ###
set-option -g @plugin "tmux-plugins/tmux-resurrect" # persists tmux environment across system restarts
set-option -g @plugin "tmux-plugins/tmux-continuum" # continuous saving of tmux environment; depends on tmux-resurrect
set-option -g @resurrect-restore "C-o" # default keybind is C-r, which is already used to reload the tmux config
set-option -g @continuum-save-interval "720" # set the save interval to every 12 hours
### Status Indicators ###
set-option -g @plugin "tmux-plugins/tmux-prefix-highlight" # highlights when you press tmux prefix key
set-option -g @plugin "tmux-plugins/tmux-battery" # battery percentage indicator
# set-option -g @plugin "tmux-plugins/tmux-online-status"
set-option -g @plugin "samoshkin/tmux-plugin-sysstat" # prints CPU usage, memory & swap, load average, net I/O metrics
### Internal Enhancements ###
# set-option -g @plugin "tmux-plugins/tmux-copycat" # enhances tmux search
# set-option -g @plugin "jaclu/tmux-menus" # popup menus to help with environment management
# set-option -g @plugin "whame/tmux-modal" # adds modes (like in Vim) for window navigation, management & resize
# set-option -g @plugin "tmux-plugins/tmux-sidebar" # sidebar w/ the directory tree for the current path
# set-option -g @plugin "kiyoon/treemux" # fork of tmux-sidebar
# set-option -g @plugin "ofirgall/tmux-window-name" # smartly names tmux windows; requires Python dependency: libtmux; TODO/FIXME: makes cursor flicker briefly when switching windows
### External Integrations ###
# set-option -g @plugin "christoomey/vim-tmux-navigator" # seamless navigation b/w tmux panes & vim splits
set-option -g @plugin "tmux-plugins/tmux-open" # quickly opens highlighted file or URL
# set-option -g @plugin "trevarj/tmux-open-nvim" # open files in a Neovim pane
# set-option -g @plugin "sainnhe/tmux-fzf" # use fzf to manage tmux work environment
# set-option -g @plugin "laktak/extrakto" # quickly select, copy/insert/complete text w/o a mouse
# set-option -g @plugin "27medkamal/tmux-session-wizard" # control session creation, naming, switching, etc. using fzf & zoxide
# set-option -g @plugin "gcla/tmux-wormhole" # download files & directories with tmux
# set-option -g @plugin "abhinav/tmux-fastcopy" # easymotion-style text copying for tmux; requires Golang compiler
# set-option -g @plugin "CrispyConductor/tmux-copy-toolkit" # various copy-mode tools inspired by several other tmux plugins
run-shell "~/.tmux/plugins/tpm/tpm" # Initialize TPM & run all plugins' scripts