-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.tmux.conf
209 lines (168 loc) · 8.52 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
#==================================================
# bind-key の -rオプション
# repeat-timeミリ秒の間, 2度目以降はprefixを入力せず
# 連続して動作を行える
set-option -g prefix C-q
set-option -g prefix2 C-s
# set-option -g prefix2 C-b
# bind -n C-s send-prefix #For using Nested tmux sessions. C-t C-t <command>
set -sg escape-time 1 # キーストロークのディレイを減らす
setw -g pane-base-index 1 # ペインのインデックスを1から始める
# 256色端末を使用する
set -g default-terminal "xterm-256color"
set-option -g xterm-keys off
# Key-bindings {{{
# Reload configuration file
bind r source-file ~/.tmux.conf \; display "Reloaded!"
#vim like split
bind c new-window
is_tmux='test `tmux -V | sed "s/\.//g" | sed "s/[a-zA-Z]*$//" | cut -d" " -f2` -gt 18'
bind s if "$is_tmux" " \
split-window -v -c '#{pane_current_path}'" " \
split-window -v"
bind v if "$is_tmux" "\
split-window -h -c '#{pane_current_path}'" "\
split-window -h "
bind '"' if "$is_tmux" " \
split-window -v -c '#{pane_current_path}'" " \
split-window -v"
has_no_fzf='!test -x `which fzf_ssh 2>/dev/null`'
fzf_ssh="ssh $(cat \
<(cat $HOME/.ssh/config /etc/hosts | \grep -i '^host' | tr \"[:blank:]\" '\\\n' | awk \"tolower(\\$1) !~/host/{print \\$1,\\$1}\" | grep -v '*') \
<(\grep -v \"^\s*#\" /etc/hosts | \grep -Fv \"0.0.0.0\") \
| awk \"{if (length(\\$2) > 0) {print \\$2}}\" | sort -u | fzf --reverse )\
"
if "$has_no_fzf" " \
bind-key S command-prompt -p \"ssh targets>\" \"tmux \$attach_nested_tmux; split-window -v 'exec ssh %%'\" " "\
bind-key S run 'tmux bind-key -n C-q send-prefix;tmux split-window -v \"\$fzf_ssh\" '\
"
if "$has_no_fzf" " \
bind-key V command-prompt -p \"ssh targets>\" \"\$attach_nested_tmux; split-window -h 'exec ssh %%'\" " "\
bind-key V run 'tmux \$attach_nested_tmux;tmux split-window -h \"\$fzf_ssh\" '\
"
if "$has_no_fzf" " \
bind-key C command-prompt -p \"ssh targets>\" \"\$attach_nested_tmux; new-window -n %1 'ssh %1'\" " "\
bind-key C run 'tmux \$attach_nested_tmux;tmux new-window \"fzf-ssh-multi_sync --reverse\" '\
"
bind-key W command-prompt -p "new session name>" "new-session -s %% -E"
bind-key - if-shell 'tmux show-options -wv synchronize-panes | grep "on"' '\
set synchronize-panes off; display-message "unsynchronized"' '\
set synchronize-panes on; display-message "synchronized"'
bind-key f new-window -n 'find-window' "tmux list-windows | grep -v \"^$(tmux display-message -p '#I'):\" | fzf --reverse | sed -E 's/:.*$//' | xargs tmux select-window -t"
bind-key F new-window -n 'find-session' "tmux list-sessions | sed -E 's/:.*$//' | grep -v \"^$(tmux display-message -p '#S')\$\" | fzf --reverse | xargs tmux switch-client -t"
bind-key ` run "tmux split-window -p 40 'tmux send-keys -t #{pane_id} \"$(mdfind / | fzf -m | paste -sd\\ -)\"'"
bind-key M run-shell "tmux split-window -h tmux-open-memo"
bind-key m run-shell "tmux display-message -p \"`cat \${JUNK:-/tmp}/tmux_pane_#{session_name}.md`\""
# Vimのキーバインドでペインを移動する
# Smart pane switching with awareness of vim splits
is_ssh='echo "#{pane_current_command}" | grep -iqE "ssh" && (( #{window_panes} < 2))'
is_vim='echo "#{pane_current_command}" | grep -iqE "(^|\/)g?(view|n?vim?)(diff)?"'
attach_nested_tmux="set-option -g prefix C-b; bind-key -n C-q send-prefix"
deteach_nested_tmux="set-option -g prefix C-q; unbind-key -n C-q "
bind -n C-h if-shell "$is_ssh || $is_vim" "$attach_nested_tmux; send-keys C-h" "$deteach_nested_tmux; select-pane -L"
bind -n C-j if-shell "$is_ssh || $is_vim" "$attach_nested_tmux; send-keys C-j" "$deteach_nested_tmux; select-pane -D"
bind -n C-k if-shell "$is_ssh || $is_vim" "$attach_nested_tmux; send-keys C-k" "$deteach_nested_tmux; select-pane -U"
bind -n C-l if-shell "$is_ssh || $is_vim" "$attach_nested_tmux; send-keys C-l" "$deteach_nested_tmux; select-pane -R"
bind -n C-\\ if-shell "$is_ssh || $is_vim" "$attach_nested_tmux; send-keys C-\\" "$deteach_nested_tmux; select-pane -l"
bind-key b set-option status
bind-key / command-prompt -p "manual>" "split-window -h 'exec man %%'"
if "test -x $(which ghq-finder-by-fzf 2>/dev/null)" "\
bind-key y new-window ghq-finder-by-fzf\
" ""
bind-key T split-window 'exec top'
bind-key Q confirm-before -p 'Do you want to kill this window?' 'run-shell "\
tmux kill-window; \
tmux if-shell \"$is_ssh\" \"$attach_nested_tmux\" \"$deteach_nested_tmux\" \
"'
# bind C-q send-key C-q #For using Nested tmux sessions. C-t C-t <command>
bind n run-shell 'tmux next-window; \
tmux if-shell "$is_ssh" "$attach_nested_tmux" "$deteach_nested_tmux"'
bind p run-shell 'tmux previous-window; \
tmux if-shell "$is_ssh" "$attach_nested_tmux" "$deteach_nested_tmux"'
bind x confirm-before -p 'Do you want to kill this pane?' 'run-shell "\
tmux kill-pane; \
tmux if-shell \"$is_ssh\" \"$attach_nested_tmux\" \"$deteach_nested_tmux\" \
"'
bind -n C-Left run-shell 'tmux previous-window; \
tmux if-shell "$is_ssh" "$attach_nested_tmux" "$deteach_nested_tmux"'
bind -n C-Right run-shell 'tmux next-window; \
tmux if-shell "$is_ssh" "$attach_nested_tmux" "$deteach_nested_tmux"'
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5
bind-key -T copy-mode-vi ? command-prompt -i -p "search up" "send -X search-backward-incremental \"%%%\""
bind-key -T copy-mode-vi / command-prompt -i -p "search down" "send -X search-forward-incremental \"%%%\""
## copy to clipboard
### for Linux
is_tmux='test `tmux -V | sed "s/\.//g" | sed "s/[a-zA-Z]*$//" | cut -d" " -f2` -gt 22 '
### for OS X
# set-option -g default-command "reattach-to-user-namespace -l $SHELL";
if-shell "which pbcopy" '\
if "$is_tmux" "\
bind-key -T copy-mode-vi v send-keys -X begin-selection; \
bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "pbcopy"; \
bind-key -T copy-mode-vi enter send-keys -X copy-pipe-and-cancel "pbcopy"; \
" "\
bind-key -T copy-mode-vi y copy-pipe \"reattach-to-user-namespace pbcopy\"; \
bind-key -T copy-mode-vi enter copy-pipe \"reattach-to-user-namespace pbcopy\"; \
" \
'
# For Ubuntu
if-shell "which xclip" '\
if "$is_tmux" "\
bind-key -T copy-mode-vi v send-keys -X begin-selection; \
bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel \"pbcopy\"; \
bind-key -T copy-mode-vi enter send-keys -X copy-pipe-and-cancel \"pbcopy\"; \
" "\
bind-key -T copy-mode-vi v send-keys -X begin-selection; \
bind-key -T copy-mode-vi y copy-pipe \"pbcopy\"; \
bind-key -T copy-mode-vi enter copy-pipe \"pbcopy\"; \
" \
'
if-shell "which win32yank.exe" '\
if "$is_tmux" "\
bind-key -T copy-mode-vi v send-keys -X begin-selection; \
bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel \"win32yank.exe -i\"; \
bind-key -T copy-mode-vi enter send-keys -X copy-pipe-and-cancel \"win32yank.exe -o\"; \
" "\
bind-key -T copy-mode-vi v send-keys -X begin-selection; \
bind-key -T copy-mode-vi y copy-pipe \"win32yank -i\"; \
bind-key -T copy-mode-vi enter copy-pipe \"win32yank -o\"; \
" \
'
set-option -g mode-keys vi
# Update default binding of `Enter` to also use copy-pipe
# }}}
setw -g aggressive-resize off
set-option -g history-limit 10000
# set-hook -g -n 'before-new-session' 'run "notify-send new-session..."'
# # マウス操作を有効にする
# set-option -g mouse off
# setw -g mode-mouse off
# set -g mouse-select-pane off
# set -g mouse-resize-pane off
# set -g mouse-select-window off
## ステータスラインの色を設定する
set -g status-bg colour235
## コマンドラインの色を設定する
# set -g message-fg white
# set -g message-bg colour235
# set -g message-attr bright
##自動リネーム
setw -g automatic-rename on
## ヴィジュアルノーティフィケーションを有効にする
setw -g monitor-activity on
set -g visual-activity on
## ステータスラインを上部に表示する
set -g status-position top
set-option -g status on
set-option -g status-interval 60
set-option -g status-justify "left"
set-option -g status-left-length 90
set-option -g status-right-length 180
run-shell "powerline-daemon -q"
if-shell 'env "$POWERLINE_CONFIG_COMMAND" tmux setup' '' 'run-shell "powerline-config tmux setup"'
set-option -g status-right "#(powerline-render tmux right)"
setw -g pane-border-status bottom
setw -g pane-border-format '#(tmux-pane-status.sh #{pane_current_path})'