-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.tmux
executable file
·215 lines (171 loc) · 6.49 KB
/
config.tmux
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
#!/usr/bin/env bash
# based on https://github.com/tmux-plugins/tmux-sensible
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# used to match output from `tmux list-keys`
KEY_BINDING_REGEX="bind-key[[:space:]]\+\(-r[[:space:]]\+\)\?\(-T prefix[[:space:]]\+\)\?"
is_osx() {
local platform=$(uname)
[ "$platform" == "Darwin" ]
}
iterm_terminal() {
[[ "$TERM_PROGRAM" =~ ^iTerm ]]
}
command_exists() {
local command="$1"
type "$command" >/dev/null 2>&1
}
# returns prefix key, e.g. 'C-a'
prefix() {
tmux show-option -gv prefix
}
# if prefix is 'C-a', this function returns 'a'
prefix_without_ctrl() {
local prefix="$(prefix)"
echo "$prefix" | cut -d '-' -f2
}
option_value_not_changed() {
local option="$1"
local default_value="$2"
local option_value=$(tmux show-option -gv "$option")
[ "$option_value" == "$default_value" ]
}
server_option_value_not_changed() {
local option="$1"
local default_value="$2"
local option_value=$(tmux show-option -sv "$option")
[ "$option_value" == "$default_value" ]
}
key_binding_not_set() {
local key="$1"
if $(tmux list-keys | grep -q "${KEY_BINDING_REGEX}${key}[[:space:]]"); then
return 1
else
return 0
fi
}
key_binding_not_changed() {
local key="$1"
local default_value="$2"
if $(tmux list-keys | grep -q "${KEY_BINDING_REGEX}${key}[[:space:]]\+${default_value}"); then
# key still has the default binding
return 0
else
return 1
fi
}
main() {
# OPTIONS (based on tmux-sensible)
# enable utf8
tmux set-option -g utf8 on
# enable utf8 in tmux status-left and status-right
tmux set-option -g status-utf8 on
# address vim mode switching delay (http://superuser.com/a/252717/65504)
#if server_option_value_not_changed "escape-time" "500"; then
tmux set-option -s escape-time 0
#fi
# increase scrollback buffer size
#if option_value_not_changed "history-limit" "2000"; then
tmux set-option -g history-limit 50000
#fi
# tmux messages are displayed for 4 seconds
tmux set-option -g display-time 4000
# required (only) on OS X
if is_osx && command_exists "reattach-to-user-namespace" && option_value_not_changed "default-command" ""; then
tmux set-option -g default-command "reattach-to-user-namespace -l $SHELL"
fi
# upgrade $TERM, tmux 1.9
if option_value_not_changed "default-terminal" "screen"; then
tmux set-option -g default-terminal "screen-256color"
fi
# upgrade $TERM, tmux 2.0+
if server_option_value_not_changed "default-terminal" "screen"; then
tmux set-option -s default-terminal "screen-256color"
fi
# use vi key bindings in tmux command prompt
tmux set-option -g status-keys vi
# use vi key bindings in copy mode
tmux set-window-option -g mode-keys vi
# increase copy buffer limit
tmux set-option buffer-limit 10
# enable mouse mode
tmux set-option -g mouse on
# make it scroll half page on wheelup/down
tmux bind-key -t vi-copy WheelUpPane halfpage-up
tmux bind-key -t vi-copy WheelDownPane halfpage-down
# focus events enabled for terminals that support them
tmux set-option -g focus-events on
# super useful when using "grouped sessions" and multi-monitor setup
if ! iterm_terminal; then
tmux set-window-option -g aggressive-resize on
fi
# MINOR KEY BINDING OPTIMIZATIONS (based on tmux-sensible)
local prefix="$(prefix)"
local prefix_without_ctrl="$(prefix_without_ctrl)"
# make sure C-b is unbound if it is not used as prefix
if [ $prefix != "C-b" ]; then
# unbind obsolte default binding
if key_binding_not_changed "C-b" "send-prefix"; then
tmux unbind-key C-b
fi
# pressing `prefix + prefix` sends <prefix> to the shell
if key_binding_not_set "$prefix"; then
tmux bind-key "$prefix" send-prefix
fi
fi
# If Ctrl-a is prefix then `Ctrl-a + a` switches between alternate windows.
# Works for any prefix character.
if key_binding_not_set "$prefix_without_ctrl"; then
tmux bind-key "$prefix_without_ctrl" last-window
fi
# source `.tmux.conf` file - as suggested in `man tmux`
if key_binding_not_set "r"; then
tmux bind-key r run-shell ' \
tmux source-file ~/.tmux.conf > /dev/null; \
tmux display-message "Sourced .tmux.conf!"'
fi
# GENERAL CUSTOMIZATIONS
# disable visual bell
tmux set-option -g bell-action any
tmux set-option -g visual-activity off
tmux set-option -g visual-bell off
# allow multiple commands under single prefix key within specified time (ms)
tmux set-option -g repeat-time 1000
# DISPLAY CUSTOMIZATIONS (edvinasme)
# start window numbers start from 1 instead of 0
tmux set-option -g base-index 1
tmux set-option -g pane-base-index 1
# update titles
tmux set-option -g set-titles on
tmux set-option -g set-titles-string ' #I-#W #T'
# Window options
tmux set-window-option -g clock-mode-style 24
tmux set-window-option -g monitor-activity on
tmux set-window-option -g xterm-keys on
tmux set-window-option -g automatic-rename on
### Theme
## Statusbar
# refresh 'status-left' and 'status-right' more often
tmux set-option -g status-interval 5
# statusbar customizations
tmux set-option -g status-justify left
tmux set-option -g status-left-length 96
tmux set-option -g status-right-length 64
tmux set-option -g status-left '#[fg=white] #(whoami)@#[fg=white,bold]#h (#S) |'
# status right (default)
#tmux set-option -g status-right '#[fg=white]| #[fg=brightred]%m/%d #[fg=white,bold]%H:%M '
# status right (tpm-battery and tpm-cpu)
tmux set-option -g status-right '#[fg=white]| batt: #{battery_percentage} CPU: #{cpu_icon}#{cpu_percentage} | #[fg=brightred]%m/%d #[fg=white,bold]%H:%M '
# windows status format
tmux set-window-option -g window-status-format ' #I-#W '
tmux set-window-option -g window-status-current-format ' #I-#W '
# custom colors
#tmux set -g status-bg yellow
#tmux set -g statuf-fg blue
tmux set -g window-status-current-bg white
tmux set -g window-status-current-attr bold
# update environment
tmux set -g update-environment "DISPLAY SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY BSPWM_SOCKET PATH"
# disable tmux starting as login shell
tmux set -g default-command "${SHELL}"
}
main