-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path.tmux.conf
82 lines (68 loc) · 3.57 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
# Reset command key to C-o
unbind-key C-b
set-option -g prefix C-o
bind-key C-o send-prefix
# Check tmux version
# https://stackoverflow.com/a/40902312/2756250
# This needs to be done even though TMUX_VERSION is set in .bashrc because .bashrc might not be sourced before starting tmux
run-shell 'tmux setenv -g TMUX_VERSION $(tmux -V | sed -En "s/^tmux ([0-9]+(.[0-9]+)?).*/\1/p")'
# Check if bc (command-line calculator) is installed and warn if not
if-shell '[ -z "$(which bc)" ]' \
'display-message "bc is not installed; needed to compare tmux versions"'
# Mouse support
if-shell '[ $(echo "$TMUX_VERSION >= 2.1" | bc) -eq 1 ]' \
'set-option -g mouse on' \
'set-option -g mode-mouse on; set-option -g mouse-resize-pane on; set-option -g mouse-select-pane on; set-option -g mouse-select-window on'
# Reload config file with prefix + r
# Need to escape semicolon or get "no target" warning (https://github.com/tmux/tmux/issues/1598)
unbind-key r
bind-key r source-file ~/.tmux.conf\; display-message 'Sourced ~/.tmux.conf'
# Source ~/.bashrc in new panes
# https://stackoverflow.com/a/45389462
set-option -g default-command "/bin/bash"
set-option -g default-shell "/bin/bash"
# Open new panes in same directory (only necessary for versions >= 1.9)
# https://unix.stackexchange.com/questions/12032/create-new-window-with-current-directory-in-tmux
if-shell '[ $(echo "$TMUX_VERSION >= 1.9" | bc) -eq 1 ]' \
'bind-key c new-window -c "#{pane_current_path}"'
# Rebind split window commands to prefix + h and prefix + v
# If version >= 1.9, need to specify to open in same directory
if-shell '[ $(echo "$TMUX_VERSION >= 1.9" | bc) -eq 1 ]' \
'bind-key h split-window -h -c "#{pane_current_path}"; bind-key v split-window -c "#{pane_current_path}"' \
'bind-key h split-window -h; bind-key v split-window -v'
# Rebind resize window commands
bind-key C-u resize-pane -U 5
bind-key C-d resize-pane -D 5
bind-key C-l resize-pane -L 5
bind-key C-r resize-pane -R 5
# Swap windows left and right
# https://unix.stackexchange.com/a/151332
# Behavior of -d flag seems to have changed in v3.0
# https://github.com/tmux/tmux/commit/3c68e51609d35189e46d9b14c2a489a5ca3de67e
if-shell '[ $(echo "$TMUX_VERSION >= 3.0" | bc) -eq 1 ]' \
'bind-key C-p swap-window -d -t -1\; display-message "Swapped window left"' \
'bind-key C-p swap-window -t -1\; display-message "Swapped window left"'
if-shell '[ $(echo "$TMUX_VERSION >= 3.0" | bc) -eq 1 ]' \
'bind-key C-n swap-window -d -t +1\; display-message "Swapped window right"' \
'bind-key C-n swap-window -t +1\; display-message "Swapped window right"'
# Pane history
set-option -g history-limit 50000
# Needed to prevent tmux yank from putting stray characters on screen
# https://github.com/tmux/tmux/issues/97
set-option -gs set-clipboard off
# Send tmux clipboard to system clipboard
# https://www.freecodecamp.org/news/tmux-in-practice-integration-with-system-clipboard-bcd72c62ff7b/
if-shell '[[ "$(uname)" == "Darwin" ]]' \
'bind-key -T copy-mode M-w send-keys -X copy-pipe-and-cancel "pbcopy"'
# List of plugins
# TODO: Restoring pane contents doesn't work
if-shell '[ $(echo "$TMUX_VERSION >= 1.9" | bc) -eq 1 ]' \
'set-option -g @plugin "tmux-plugins/tpm" ; \
set-option -g @plugin "tmux-plugins/tmux-resurrect" ; \
set-option -g @resurrect-capture-pane-contents "on" ; \
set-option -g @resurrect-save "S" ; \
set-option -g @resurrect-restore "R"'
# Initialize tmux plugin manager
# This line must be at the very bottom of .tmux.conf
if-shell '[ $(echo "$TMUX_VERSION >= 1.9" | bc) -eq 1 ]' \
'run -b "~/.tmux/plugins/tpm/tpm"'