-
Notifications
You must be signed in to change notification settings - Fork 1
/
.tmux.conf
205 lines (160 loc) · 10.4 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
################################################################
# from <https://www.hamvocke.com/blog/a-guide-to-customizing-your-tmux-conf/>
################################################################
# remap prefix from 'C-b' to 'C-a'
unbind C-b
set-option -g prefix C-a
bind-key -T prefix a send-prefix
# split panes using | and -
bind | split-window -h
bind - split-window -v
unbind '"'
unbind %
# use colors in the terminal (this otherwise seems to like using just plain 'screen'
set -g default-terminal tmux-256color
################################################################
# used to have Ctrl-A switch to the last window, like screen
# from <https://superuser.com/questions/429558/how-to-switch-between-two-latest-windows-in-tmux/429560#429560>
bind-key C-a last-window
# use <prefix>A to rename the window title, like with screen
bind-key -T prefix A command-prompt -p 'new name:' 'rename-window "%1"'
# rebind to use hjkl keys instead of arrow keys to switch panes
bind h select-pane -L
bind j select-pane -D
#bind k select-pane -U # interferes with using 'k' to kill the current window, so disabling this for now
bind l select-pane -R
# if we want to unbind the arrow keys for that:
# from <https://superuser.com/questions/463282/tmux-unbind-arrow-keys/463286#463286>
unbind Left
unbind Down
unbind Up
unbind Right
################################################################
##Status line###################################################
################################################################
#set -g status-left %f\ %m\ \ ft=%y\ \ char=%b,\ %B,\ #%o,\ #%O%=%l(%L),%c\ \ \ \ \ \ \ %p%% #stl; determines what to show in the status line; the
#default is: statusline=%-f\ %-m%=%l,%c\ \ \ \ \ \ \ %P; help default is: statusline=%-t\ %-h%-r%=%l,%c%V\ \ \ \ \ \ \ %P
# statusline
set -g status on
set -g status-interval 5 # refresh the status line every 5 seconds instead of the default 15
set -g status-style 'bg=black'
set -g status-left-length 30
# editorconfig-checker-disable
set -g status-left "#{?client_prefix,#[fg=colour254]#[bg=colour31]#[bold],[}#[fg=brightyellow,bg=black]#{host}#{?client_prefix,#[fg=colour254]#[bg=colour31]#[bold],#[default]]}#[default]#[fg=brightgreen,dim]["
set -g status-justify "centre"
#set-window-option -g window-status-format "#[fg=brightgreen]#I #{pane_current_path}: #W#F"
#set-window-option -g window-status-format "#[fg=brightgreen]#I #{s|$HOME|~|;s|/.*/|/…/|:pane_current_path}: #W#F" # from https://unix.stackexchange.com/questions/260147/tmux-status-line-and-current-path-format/598896#598896
set-window-option -g window-status-format "[#[bold]#{?#{==:#{window_flags},-},#[fg=brightyellow],#[fg=brightcyan]}#{window_index} #{?#{==:#{window_flags},-},#[fg=brightyellow],#[fg=blue,bold]}#(echo #{pane_current_path} | sed -rne 's;$HOME;~;p;s;^(~?.).*\/([^/]+\/[^/]+);\\1…/\\2;p')#[default]: #{window_name}#{?window_flags,#{window_flags}, }#[default]]"
set-window-option -g window-status-current-format "#[bold]#[fg=red](#[fg=brightgreen]#{window_index} #(echo #{pane_current_path} | sed -rne 's;$HOME;~;p;s;^(~?.).*\/([^/]+\/[^/]+);\\1…/\\2;p')#[default]: #{window_name}#[fg=red,bold] )"
# the maximum width here is about 20 characters, so we cut it off at 16
set -g status-right '#[fg=green]][#[fg=terminal]#($HOME/.tmux/dracula/scripts/weather.sh false false 2>&1 | sed -re "s;(.{16}).*;\1;") #[fg=brightcyan]%Y-%m-%d #[fg=brightgreen]%H:%M#[fg=brightgreen,dim]]'
# editorconfig-checker-enable
set-window-option -g window-status-separator ' '
# for dracula support, you have to download the relevant files first:
# for file in weather sleep_weather; do
# curl -so ~/.tmux/dracula/scripts/${file}.sh https://raw.githubusercontent.com/dracula/tmux/master/scripts/${file}.sh;
# done
# and just change this line for the display in weather.sh:
# echo "$(display_weather) ($(curl -sL wttr.in\?format="%t&u" | egrep -o '[0-9]+°[FC]' | tr -d '\n'))$(display_location)"
# and also this line:
# curl -sL wttr.in/$(curl -s https://ipinfo.io/city 2> /dev/null | tr ' ' '+')\?format="%C+%t$display_weather"
#caption always "%{= kC}[%{C}%H]%{g}[%= %{= kG}%?%-w%?%{r}(%{C}%n %f%t%?(%u)%?%{r})%{G}%?%+w%?%?%= %{g}][%{C}%m/%d/%Y %{G}%c%{g}]"
################################################################
# from <https://stackoverflow.com/questions/51084097/unable-to-set-tmux-window-title-to-current-program/54061103#54061103>
# supposed to enforce panes updating their name when they should, which doesn't always happen, in my experience
#set -g automatic-rename on
#set -g automatic-rename-format "#{?pane_in_mode,[tmux],#{pane_current_command}}#{?pane_dead,[dead],}"
# removes the default 500 millisecond delay after entering Esc (or Ctrl+[)
# though to fully remove the delay, it may take setting something with terminal
# referenced here:
# https://www.johnhawthorn.com/2012/09/vi-escape-delays/
set -s escape-time 0
################################################################
# from <https://superuser.com/questions/463282/tmux-unbind-arrow-keys/1042443#1042443>
################################################################
# vim-like pane resizing
bind -r -N "Resize the pane up by 5" C-k resize-pane -U 5
bind -r -N "Resize the pane down by 5" C-j resize-pane -D 5
bind -r -N "Resize the pane left by 5" C-h resize-pane -L 5
bind -r -N "Resize the pane right by 5" C-l resize-pane -R 5
bind -r -N "Resize the pane up by 1" Up resize-pane -U
bind -r -N "Resize the pane down by 1" Down resize-pane -D
bind -r -N "Resize the pane left by 1" Left resize-pane -L
bind -r -N "Resize the pane right by 1" Right resize-pane -R
## vim-like pane switching
#bind -r h select-pane -L
#bind -r k select-pane -U
#bind -r j select-pane -D
#bind -r l select-pane -R
# and now unbind keys
#unbind Up
#unbind Down
#unbind Left
#unbind Right
unbind C-Up
unbind C-Down
unbind C-Left
unbind C-Right
################################################################
# from <https://til.hashrocket.com/posts/d4d3c1fea6-quickly-edit-and-reload-tmux-configuration>
bind-key R source-file ~/.tmux.conf \; display-message "~/.tmux.conf reloaded"
#bind-key -T copy-mode-vi C-a ] send-keys paste-buffer
#bind-key -r C-] send-keys -X paste-buffer
#bind-key -T copy-mode-vi Space send-keys -X copy-selection-and-cancel
# use paste bracket control codes when necessary, such as in vim
# <https://github.com/tmux/tmux/issues/2248>
# <https://github.com/tmux/tmux/commit/5d69b9c4a7e8adc570e965189de0e5936fbf8e1c>
unbind-key -T prefix ]
bind-key -T prefix ] paste-buffer -p
# vim-like copy mode
# from <https://superuser.com/questions/395158/tmux-copy-mode-select-text-block/693990#693990>
unbind-key -T copy-mode-vi v
# Begin selection in copy mode.
bind-key -T copy-mode-vi 'v' if-shell -F '#{selection_present}' 'send-keys -X copy-selection-and-cancel' 'send-keys -X begin-selection'
# Begin rectangle selection in copy mode.
bind-key -T copy-mode-vi 'C-v' "send-keys -X begin-selection; send-keys -X rectangle-toggle"
# <https://superuser.com/questions/1069902/tmux-configuration-stanzas-based-on-tmux-version/1151663#1151663>
# <https://stackoverflow.com/questions/35016458/how-to-write-if-statement-in-tmux-conf-to-set-different-options-for-different-t/40902312#40902312>
# <https://unix.stackexchange.com/questions/131011/use-system-clipboard-in-vi-copy-mode-in-tmux/131187#131187>
# this goes over a way to add support for copying terminal content over ssh to the local clipboard:
# https://www.freecodecamp.org/news/tmux-in-practice-integration-with-system-clipboard-bcd72c62ff7b/
# I had to use `xsel` since `clipit` doesn't seem to actually save standard input, and it's not maintained very well
if-shell 'which xsel &>/dev/null' "\
bind-key -T copy-mode-vi 'y' send-keys -X copy-pipe-and-cancel 'xsel -b'"
# moved to ~/.shellrc.d/base since it won't work here
# this command would otherwise result in the following error if in ~/.tmux.conf since tmux seems to read and execute the conf file in full before
# creating a session:
# .tmux.conf:117: no current target
# more info at <https://superuser.com/questions/1413870/tmux-conf-doesnt-work-when-starting-but-does-with-source-file/1414127#1414127>
#new-window top
# remap session and window killer keys
bind-key -T prefix \\ confirm-before -p "kill-session #{session_name}? (y/n)" kill-session
bind-key -T prefix k confirm-before -p "kill-window #{window_name}? (y/n)" kill-window
unbind -T prefix t # unset the default "clock" mode key binding
bind-key -T prefix t choose-tree -Zs # move the default prefix-s to prefix-t
unbind -T prefix s # unset the default "choose-tree" key binding
# from <https://unix.stackexchange.com/questions/26548/write-all-tmux-scrollback-to-a-file/26568#26568>
bind-key -T prefix s command-prompt -p 'save history to filename:' -I '~/tmux.history' 'capture-pane -S -32768 ; save-buffer %1 ; delete-buffer'
# change <prefix>= to overwrite the current buffer with the chosen buffer
# from <https://unix.stackexchange.com/questions/646582/how-do-i-set-a-previous-paste-buffer-in-tmux-back-to-the-active-buffer/646695#646695>
unbind-key -T prefix =
bind-key -T prefix = choose-buffer -Z "run \"tmux saveb -b %% - | tmux loadb -\""
# possible solution for being able to copy output within pagers, like less
# from <https://www.reddit.com/r/tmux/comments/8car73/is_it_possible_to_have_prefixless_and_pager/e1ufoyw/>
# tmux bind-key -n PPage if -F '#{alternate_on}' 'send-keys PPage' 'copy-mode -eu'
# copy the SESSION_MANAGER variable from the main environment so vim doesn't have a delay, as shown via this command:
# $ vim -u NONE --startuptime /dev/stdout -c q
# from <https://blog.lxgr.net/posts/2014/05/15/vim-tmux-startup-delay/>
set-option -g -a update-environment " SESSION_MANAGER"
set -g history-limit 50000
set -g @plugin 'dracula/tmux'
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# HANDY COMMANDS
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# show-options -g # show; shows the live config: global tmux options and their values, including those set in this file
# list-keys # lsk; shows the live key bindings, including those set in this file
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# HANDY KEYSTROKES
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# <prefix>= # shows the copy-mode history so you can interactively select and reuse copied text older than the one currently in the buffer
# <prefix># # shows the copy-mode history so you can review text older than the one currently in the buffer