tmux - Terminal Multiplexerjava.ociweb.com/mark/other-presentations/tmux.pdf · tmux Overview...

22
tmux - Terminal Multiplexer Mark Volkmann [email protected]

Transcript of tmux - Terminal Multiplexerjava.ociweb.com/mark/other-presentations/tmux.pdf · tmux Overview...

Page 1: tmux - Terminal Multiplexerjava.ociweb.com/mark/other-presentations/tmux.pdf · tmux Overview Dramatically expands what can be done with terminal windows Alternative to older program

tmux - Terminal Multiplexer

Mark [email protected]

Page 2: tmux - Terminal Multiplexerjava.ociweb.com/mark/other-presentations/tmux.pdf · tmux Overview Dramatically expands what can be done with terminal windows Alternative to older program

tmux

Overview

Dramatically expands what can be donewith terminal windowsAlternative to older program named “screen”Often used for interactive server sessions

that can survive network disconnections

2

Page 3: tmux - Terminal Multiplexerjava.ociweb.com/mark/other-presentations/tmux.pdf · tmux Overview Dramatically expands what can be done with terminal windows Alternative to older program

tmux

Book

tmux: Productive Mouse-Free DevelopmentBrian P. Hogan

Pragmatic Programmers

3

Page 4: tmux - Terminal Multiplexerjava.ociweb.com/mark/other-presentations/tmux.pdf · tmux Overview Dramatically expands what can be done with terminal windows Alternative to older program

tmux

For You?

Do you work in a Unixey environment?Do you frequently use terminal windows?Do you value using keyboard shortcuts?

4

Page 5: tmux - Terminal Multiplexerjava.ociweb.com/mark/other-presentations/tmux.pdf · tmux Overview Dramatically expands what can be done with terminal windows Alternative to older program

tmux

tmux Commands

Large number of themMany ways to execute

command-line

shell script

command mode in tmux client

keyboard shortcut in tmux client

tmux configuration file

5

Page 6: tmux - Terminal Multiplexerjava.ociweb.com/mark/other-presentations/tmux.pdf · tmux Overview Dramatically expands what can be done with terminal windows Alternative to older program

tmux

Key Bindings

Prefix keyC-b by default; many change to C-a

Meta keyabbreviated as M; cmd-option on Mac

Commandslist-keys or prefix ?

bind-key [-r] {key} {command}

-r allows repeated used without prefix

unbind-key {key}

6

Page 7: tmux - Terminal Multiplexerjava.ociweb.com/mark/other-presentations/tmux.pdf · tmux Overview Dramatically expands what can be done with terminal windows Alternative to older program

tmux

Terminology

serverclientsessionwindowpanestatus bar

7

Page 8: tmux - Terminal Multiplexerjava.ociweb.com/mark/other-presentations/tmux.pdf · tmux Overview Dramatically expands what can be done with terminal windows Alternative to older program

tmux

Sample Session

Demo time!

8

Page 9: tmux - Terminal Multiplexerjava.ociweb.com/mark/other-presentations/tmux.pdf · tmux Overview Dramatically expands what can be done with terminal windows Alternative to older program

tmux

Session Actions

newdetachattachlistrenameswitch - one being displayedkill

9

Page 10: tmux - Terminal Multiplexerjava.ociweb.com/mark/other-presentations/tmux.pdf · tmux Overview Dramatically expands what can be done with terminal windows Alternative to older program

tmux

Window Actions

newrenameswitch - one being viewedlistmove - to a different sessionkill

10

Page 11: tmux - Terminal Multiplexerjava.ociweb.com/mark/other-presentations/tmux.pdf · tmux Overview Dramatically expands what can be done with terminal windows Alternative to older program

tmux

Pane Actions

new - via splitswitch - one that is activechange layoutresizerotate - to change position of allswap - to change position of twomove - to different windowexecute command - from a script into a specific panekill

11

Page 12: tmux - Terminal Multiplexerjava.ociweb.com/mark/other-presentations/tmux.pdf · tmux Overview Dramatically expands what can be done with terminal windows Alternative to older program

tmux

Predefined Pane Layouts ...

even-horizontal

12

even-vertical

Page 13: tmux - Terminal Multiplexerjava.ociweb.com/mark/other-presentations/tmux.pdf · tmux Overview Dramatically expands what can be done with terminal windows Alternative to older program

tmux

... Predefined Pane Layouts

main-horizontalmain-verticaltiled

13

Page 14: tmux - Terminal Multiplexerjava.ociweb.com/mark/other-presentations/tmux.pdf · tmux Overview Dramatically expands what can be done with terminal windows Alternative to older program

tmux

Buffers

Each pane has a buffer that storescommands entered and their output

has a limited size that defaults to 2000 lines

Enter “copy mode” toscroll through and copy linesEach copy adds a “paste buffer” to a stack

has a limited size that defaults to 20

14

Page 15: tmux - Terminal Multiplexerjava.ociweb.com/mark/other-presentations/tmux.pdf · tmux Overview Dramatically expands what can be done with terminal windows Alternative to older program

tmux

Copy Mode Actions

enter copy modeexit copy modemove cursorcopy selected textcopy all visible textlist paste buffersview paste buffer contents

save paste buffercontent to a filepaste text froma paste bufferchange paste bufferstack sizedelete one paste bufferdelete all paste buffers

15

Page 16: tmux - Terminal Multiplexerjava.ociweb.com/mark/other-presentations/tmux.pdf · tmux Overview Dramatically expands what can be done with terminal windows Alternative to older program

tmux

Configuration Options

Three kindsserver

session

window

Option scopeglobal

specific session

specific window

Actionsset option

show option

16

Page 17: tmux - Terminal Multiplexerjava.ociweb.com/mark/other-presentations/tmux.pdf · tmux Overview Dramatically expands what can be done with terminal windows Alternative to older program

tmux

Configuration Files

Looks for ~/.tmux.conf firstThen looks for /etc/tmux.confLet’s examine mine!

17

Page 18: tmux - Terminal Multiplexerjava.ociweb.com/mark/other-presentations/tmux.pdf · tmux Overview Dramatically expands what can be done with terminal windows Alternative to older program

tmux

Scripting

Consider creating one setup script for each projectCreates a new project session if it doesn’t exist

creates windows

splits them into panes

starts commands in some windowsex. editor, file watching apps, ssh, ...

Otherwise, attaches to existing sessionLet’s examine one of mine!

18

Page 19: tmux - Terminal Multiplexerjava.ociweb.com/mark/other-presentations/tmux.pdf · tmux Overview Dramatically expands what can be done with terminal windows Alternative to older program

tmux

Collaboration

ssh to a remote serverStart a tmux session thereAsk others to

ssh to same remote server

attach to same tmux session

Collaborate!

19

Page 20: tmux - Terminal Multiplexerjava.ociweb.com/mark/other-presentations/tmux.pdf · tmux Overview Dramatically expands what can be done with terminal windows Alternative to older program

tmux

Multiple Monitors

Run client in first monitor attached to main sessionRun client in other monitors attached to a new session that is “grouped” with main sessionAllows each client to viewa different window in main sessionSet window option “aggressive-resize” to “on”

allows each client window to be a different size

20

Page 21: tmux - Terminal Multiplexerjava.ociweb.com/mark/other-presentations/tmux.pdf · tmux Overview Dramatically expands what can be done with terminal windows Alternative to older program

tmux

Mac Specific Advice

Use iTerm2Change some System PreferencesChange some iTerm2 PreferencesFor details, see my OCI SETT article

http://sett.ociweb.com/sett/settJan2013.html

21

Page 22: tmux - Terminal Multiplexerjava.ociweb.com/mark/other-presentations/tmux.pdf · tmux Overview Dramatically expands what can be done with terminal windows Alternative to older program

tmux

Thanks For Listening!

[email protected]

22