-
Notifications
You must be signed in to change notification settings - Fork 7
/
.tmux.conf
244 lines (192 loc) · 9.16 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
# ~/.tmux.conf - tmux terminal multiplexer config
# Ches Martin (http://chesmart.in/)
###########################################################################
# Global Settings #
###########################################################################
# Use the OS X pasteboard hack if available
if 'command -v reattach-to-user-namespace >/dev/null' \
'set -gq @osx-pasteboard true'
# Requests a login shell because this is both macOS and tmux norm.
# https://superuser.com/q/968942/79564
if -F '#{@osx-pasteboard}' \
'set -g default-command "reattach-to-user-namespace -l $SHELL"'
if 'command -v fpp >/dev/null' \
'set -gq @has-fpp true'
# tmux is supposed to figure out 256-color support from terminfo and set this,
# but it seems to fail anyway. Kind of sucks for when I run Terminal.app...
# TODO: we can use shell here to be smart-ish
set -g default-terminal "screen-256color"
# set prefix key to match screen's
set -g prefix C-a
unbind-key C-b
# send the prefix to client inside window (ala nested sessions)
bind-key a send-prefix
# disable wait after escape, so vim is usable
set -sg escape-time 0
# in copy mode, use vi bindings and make the mouse work
setw -g mode-keys vi
setw -g mouse on
# Ctrl-p/n for tmux command history -- the vi mode is more like shell vi mode
# than vi command mode
set -g status-keys emacs
# scrollback buffer n lines
set -g history-limit 12000
# bells and monitoring
set -g bell-action any
set -g visual-bell on
set -g visual-activity on
set -g visual-silence on
# This was removed -- what happened to it?
# set -g visual-content on
# purdy status bar -- see FORMATS section of the man page
set -g status-bg colour236
set -g status-fg white
set -g status-left "#[fg=green][#[fg=cyan]#S#[fg=green]]#[fg=colour250] %a %b %d %H:%M#[default]"
set -g status-left-length 35
set -g status-justify centre
setw -g window-status-current-format '#[fg=black,bg=yellow] #I #[fg=white,bg=colour98] #W #F '
setw -g window-status-current-style 'bg=colour98 bold'
set -g status-right "#[fg=colour250]#H #[fg=cyan][#(uptime|cut -d ' ' -f 12-)]#[default]"
# set -g message-attr bold
# set -g message-fg black
# set -g message-bg yellow
# try to set wm window titles, with xterm escape sequences
set -g set-titles on
# wm window title string (uses statusbar variables)
# set -g set-titles-string "#I:#W"
# Zero-based indexing for windows and panes isn't terribly sensible.
set -g base-index 1
setw -g pane-base-index 1
# the panes display and status messages don't show very long by default
set -g display-panes-time 2000
set -g display-time 2000
# If we want Vim to be told about focus: http://git.io/2UqSgQ
set -g focus-events on
# In case https://direnv.net is loaded when invoking tmux, unload it so the
# active environment doesn't pollute tmux's
set -g update-environment "DIRENV_DIFF DIRENV_DIR DIRENV_LAYOUT DIRENV_WATCHES"
setenv -gu DIRENV_DIFF ; setenv -gu DIRENV_DIR ; setenv -gu DIRENV_LAYOUT
setenv -gu DIRENV_WATCHES
###########################################################################
# Key Bindings - Screen and Vim-ish #
###########################################################################
# I'm leaving some unbinds for defaults commented out, as I attempt to
# train myself on some tmux defaults that I like better than screen's
# reload settings
bind-key R source-file ~/.tmux.conf \; display-message "tmux config reloaded"
# toggle previous window like screen, although prefix-l will
# be easy to get used to
bind-key C-a last-window
# vim-ish movement between and resizing of panes
bind-key -r C-h select-pane -L
bind-key -r C-j select-pane -D
bind-key -r C-k select-pane -U
bind-key -r C-l select-pane -R
bind-key -r < resize-pane -L 3
bind-key -r > resize-pane -R 3
bind-key -r J swap-pane -D
bind-key -r K swap-pane -U
bind-key -r M-, swap-window -t -1
bind-key -r M-. swap-window -t +1
# remap kill window, add confirm map before killing server
unbind &
bind-key Q confirm kill-window
bind-key X confirm kill-server
# Monitoring toggles
bind-key m setw monitor-activity \; display-message 'monitoring window activity [#{?monitor-activity,ON,OFF}]'
bind-key M if -F '#{monitor-silence}' \
'setw monitor-silence 0 ; display-message "monitoring window silence [OFF]"' \
'command-prompt -p "monitor silence: interval (s)" "setw monitor-silence %%"'
# name window
unbind ,
bind-key A command-prompt -I "#W" "rename-window %%"
# Session switching. "H" for "home", comma will accept a prefix string
bind-key H switchc -t main
bind-key , command-prompt -p "switch to session:" "switch-client -t '%%'"
bind-key C command-prompt -p "create session named:" "new-session -s %%"
# Make copy mode more vim-like.
bind-key -Tcopy-mode-vi v send -X begin-selection
bind-key -Tcopy-mode-vi y send -X copy-selection
bind-key -Tcopy-mode-vi C-v send -X rectangle-toggle
# Copy top of tmux paste buffer stack to OS clipboard.
# Alternatively, this will always immediately copy to system pasteboard:
# bind-key -Tcopy-mode-vi y send -X copy-pipe "reattach-to-user-namespace pbcopy"
if -F '#{@osx-pasteboard}' \
'bind y run "tmux save-buffer - | reattach-to-user-namespace pbcopy"'
# mnemonic split bindings
# unbind %
# unbind '"'
bind | split-window -h
bind - split-window -v
# Load a named session
# Without completion mechanisms for tmux commands, I can't think of anything
# easier than naming conventions to do this for now. Probably some worthy ideas
# in: https://github.com/tmux-plugins/tmux-sessionist
bind-key S command-prompt -p "load saved session named:" \
'if "tmux has-session -t %%" \
"display-message \"a session named %1 already exists!\"" \
"source-file ~/.tmux/sessions/%1.conf ; switchc -t %1"'
# Interactively select session file to load. Mnemonic: Browse
# TODO: need a way to switch to detached sessions when launched
bind-key B if -F '#{@has-fpp}' \
"new-window -n session-select \
'sh -c \"find ~/.tmux/sessions | fpp --non-interactive -c tmux\ source-file\"'" \
'display-message "fpp not installed!"'
# I like to quickly pop open a short shell from fullscreen apps like vim, IRC
# TODO: prevent creating a second lower split in the case that one is open
bind-key _ if -F '#{window_zoomed_flag}' \
'resize-pane -Z ; select-pane -t:.+1' \
'split-window -l 10'
# "hide", return to last pane and zoom it. Compliments the above _
bind-key h select-pane -l \; resize-pane -Z
# whizbang custom keybindings
bind-key F1 command-prompt -p "Man:" "split-window -h 'exec man %%'"
bind-key @ command-prompt -p "SSH:" "new-window -n %1 'ssh %1'"
bind-key / copy-mode \; send-keys ?
# Toggle piping output from a pane to file
# Can't see a simple way to indicate activated or deactivated :-/
# For external scripts see https://github.com/tmux-plugins/tmux-logging
bind-key P pipe-pane -o 'cat >> ~/.tmux/logs/#S-#W-#T.out' \;\
display-message "toggled logging of pane to ~/.tmux/logs/#S-#W-#T.out"
# present a menu of URLs to open from the visible pane. sweet.
bind-key U capture-pane \;\
save-buffer /tmp/tmux-buffer \;\
delete-buffer \;\
split-window -l 10 "urlview /tmp/tmux-buffer"
# shortcut to seed fpp file selector with pane contents.
# idea courtesy of https://github.com/tmux-plugins/tmux-fpp
bind-key F capture-pane -J \;\
save-buffer /tmp/tmux-buffer \;\
delete-buffer \;\
new-window -n fpp -c '#{pane_current_path}' "sh -c 'cat /tmp/tmux-buffer | fpp ; rm /tmp/tmux-buffer'"
# This ugliness makes mouse scrolling a pane "Just Work" the way it did before
# tmux 2.1. This will probably be a default mapping in the next version:
# https://github.com/tmux/tmux/issues/145
# Change the end to `'copy-mode -e; send-keys -M'` to start scroll immediately
bind -n WheelUpPane select-pane -t = \;\
if -t = -F "#{mouse_any_flag}" "send-keys -M" \
"if -t = -F '#{pane_in_mode}' 'send-keys -M' 'copy-mode -e'"
#######################################################################
# Plugins #
#######################################################################
# Worth a look for some scrolling improvements:
# https://github.com/NHDaly/tmux-better-mouse-mode
set -g @continuum-save-interval '30'
run-shell ~/.tmux/plugins/tmux-resurrect/resurrect.tmux
run-shell ~/.tmux/plugins/tmux-continuum/continuum.tmux
set -g @resurrect-capture-pane-contents 'on'
#######################################################################
# Session Initialization #
#######################################################################
# need a default session despite the conditionals below
new-session -d -s default
# Default session setups for certain hosts
if '[ `hostname -s` = lupin ] && ! tmux has-session -t main' \
'source-file $HOME/.tmux/lupin.conf'
if '[ `hostname -s` = kodama ] && ! tmux has-session -t main' \
'source-file $HOME/.tmux/kodama.conf'
if '[ `hostname -s` = Fio ] && ! tmux has-session -t main' \
'source-file $HOME/.tmux/fio.conf'
# If we started one of the preconfigured sessions, use it and kill the default
if 'tmux has-session -t main && tmux has-session -t default' \
'switch-client -t main; kill-session -t default'