This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tmux.html
329 lines (227 loc) · 8.12 KB
/
tmux.html
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>tmux</title>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="lib/reveal.js/css/reveal.min.css">
<link rel="stylesheet" href="lib/reveal.js/css/theme/night.css">
<link rel="stylesheet" href="lib/template.css">
<!-- For syntax highlighting -->
<link rel="stylesheet" href="lib/reveal.js/lib/css/zenburn.css">
<!-- If the query includes 'print-pdf', include the PDF print sheet -->
<script>
if( window.location.search.match( /print-pdf/gi ) ) {
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = 'css/print/pdf.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
}
</script>
<!--[if lt IE 9]>
<script src="lib/reveal.js/lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<div class="slides" id="content">
<section data-markdown
data-separator="==="
data-vertical="---"><script type="text/template">
# tmux
**5 minutes to love it!**
===
## Why?
---
### 1-second terminal setup
![](tmux/tmux-tmuxifier-demo-project-setup.gif)
---
### Look 'ma, no hands!
![](tmux/look-ma-no-hands.jpg)
---
### Copy/paste your session history
![](tmux/tmux-tmuxifier-demo-copy-paste.gif)
---
### Search your history
![](tmux/tmux-tmuxifier-demo-search-history.gif)
===
## Getting started
---
### Install
**tmux**
```sh
$ brew install tmux
```
**tmuxifier**
```sh
$ git clone https://github.com/jimeh/tmuxifier.git ~/.tmuxifier
$ echo 'export PATH="$HOME/.tmuxifier/bin:$PATH"' >> ~/.zshrc
$ echo 'eval "$(tmuxifier init -)"' >> ~/.zshrc
```
===
## Cheatsheets
---
### tmuxifier
```sh
$ tmuxifier new-window project
$ tmuxifier new-session project
$ tmuxifier load-session project
```
---
### tmux
**Start new session**
```sh
$ tmux new -s session_name
```
**Attach to existing session**
```sh
$ tmux a -t session_name
```
**Kill an existing session**
<small>_This will kill (most of) the processes running in the session_</small>
```sh
$ tmux kill-session -t session_name`: kills the session and its processes
```
---
### Inside Tmux
- Cycle panes: `ctrl-b o`
- Change pane: `ctrl-b <arrow>`
- Enter copy-mode: `ctrl-b [`
- Detach from the session: `ctrl-b d` (processes will continue to run, you're only not showing them anymore!)
Check [this cheatsheet](https://gist.github.com/MohamedAlaa/2961058) and [this one](https://gist.github.com/MohamedAlaa/2961058) for more.
===
## Config examples
---
### Easier tmux bindings
<small>Especially for vi users!</small>
```sh
# Ring the bell if any background window rang a bell
set -g bell-action any
# Default termtype. If the rcfile sets $TERM, that overrides this value.
set -g default-terminal screen-256color
# Keep your finger on ctrl, or don't
bind-key ^D detach-client
# Create splits and vertical splits
bind-key v split-window -h -p 50 -c "#{pane_current_path}"
bind-key ^V split-window -h -p 50 -c "#{pane_current_path}"
bind-key s split-window -p 50 -c "#{pane_current_path}"
bind-key ^S split-window -p 50 -c "#{pane_current_path}"
# Pane resize in all four directions using vi bindings.
# Can use these raw but I map them to shift-ctrl-<h,j,k,l> in iTerm.
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
# Smart pane switching with awareness of vim splits.
# Source: https://github.com/christoomey/vim-tmux-navigator
bind -n C-h run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)g?(view|vim?)(diff)?$' && tmux send-keys C-h) || tmux select-pane -L"
bind -n C-j run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)g?(view|vim?)(diff)?$' && tmux send-keys C-j) || tmux select-pane -D"
bind -n C-k run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)g?(view|vim?)(diff)?$' && tmux send-keys C-k) || tmux select-pane -U"
bind -n C-l run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)g?(view|vim?)(diff)?$' && tmux send-keys C-l) || tmux select-pane -R"
bind -n C-\ run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)g?(view|vim?)(diff)?$' && tmux send-keys 'C-\\') || tmux select-pane -l"
# Use vi keybindings for tmux commandline input.
# Note that to get command mode you need to hit ESC twice...
set -g status-keys vi
# Use vi keybindings in copy and choice modes
setw -g mode-keys vi
# easily toggle synchronization (mnemonic: e is for echo)
# sends input to all panes in a given window.
bind e setw synchronize-panes on
bind E setw synchronize-panes off
# set first window to index 1 (not 0) to map more to the keyboard layout...
set-option -g base-index 1
set-window-option -g pane-base-index 1
# color scheme (styled as vim-powerline)
set -g status-left-length 52
set -g status-right-length 451
set -g status-fg white
set -g status-bg colour234
set -g pane-border-fg colour245
set -g pane-active-border-fg colour39
set -g message-fg colour16
set -g message-bg colour221
set -g message-attr bold
set -g status-left '#[fg=colour235,bg=colour252,bold] ❐ #S #[fg=colour252,bg=colour238,nobold]⮀#[fg=colour245,bg=colour238,bold] #(whoami) #[fg=colour238,bg=colour234,nobold]⮀'
set -g window-status-format "#[fg=colour235,bg=colour252,bold] #I #W "
set -g window-status-current-format "#[fg=colour234,bg=colour39]⮀#[fg=black,bg=colour39,noreverse,bold] #I: #W #[fg=colour39,bg=colour234,nobold]⮀"
# Patch for OS X pbpaste and pbcopy under tmux.
set-option -g default-command "which reattach-to-user-namespace > /dev/null && reattach-to-user-namespace -l $SHELL || $SHELL"
# Screen like binding
unbind C-b
set -g prefix C-a
bind a send-prefix
# No escape time for vi mode
set -sg escape-time 0
# Screen like binding for last window
unbind l
bind C-a last-window
# Bigger history
set -g history-limit 10000
# New windows/pane in $PWD
bind c new-window -c "#{pane_current_path}"
# force a reload of the config file
unbind r
bind r source-file ~/.tmux.conf \; display "Reloaded!"
# Local config
if-shell "[ -f ~/.tmux.conf.user ]" 'source ~/.tmux.conf.user'
```
See [my tmux.conf](https://github.com/rchampourlier/dotfiles/blob/master/tmux/tmux.conf)
---
### tmuxifier window example for JobTeaser
**~/.tmuxifier/layouts/jobteaser-main.window.sh**
```sh
# Set window root path. Default is `$session_root`.
# Must be called before `new_window`.
window_root "/path/to/jobteaser"
new_window "jobteaser-main"
# Split window into 4 panes (top panes are 70% of the
# screen height, all panes are 50% of the width).
# 1: top-left (shell)
# 2: top-right (rails console)
# 3: bottom-left (rails server)
# 4: bottom-right (tunnelss)
split_h 50
split_v 30 1
split_v 30 2
# Run commands to setup panes
run_cmd "bundle exec rails console" 2
run_cmd "bundle exec rails server" 3
run_cmd "sudo tunnelss" 4
# Set active pane.
select_pane 1
```
---
### tmuxifier session example
```sh
# Set a custom session root path. Default is `$HOME`.
# Must be called before `initialize_session`.
#session_root "~"
# Create session with specified name if it does not already exist. If no
# argument is given, session name will be based on layout file name.
if initialize_session "jobteaser"; then
# Create a new window inline within session layout definition.
#new_window "misc"
# Load a defined window layout.
load_window "jobteaser-main"
# Select the default active window on session creation.
#select_window 1
fi
# Finalize session creation and switch/attach to it.
finalize_and_go_to_session
```
===
## Questions?
===
## Have fun and share!
</script></section>
</div>
</div>
<script src="lib/reveal.js/lib/js/head.min.js"></script>
<script src="lib/reveal.js/js/reveal.min.js"></script>
<script src="lib/jquery/dist/jquery.min.js"></script>
<script src="config.js"></script>
</body>
</html>