31
TMUX Development workflow

Tmux Development Workflow

Embed Size (px)

Citation preview

Page 1: Tmux Development Workflow

TMUXDevelopment workflow

Page 2: Tmux Development Workflow

What does it do?

Page 3: Tmux Development Workflow

Multiple panes

Page 4: Tmux Development Workflow

Multiple windows

Page 5: Tmux Development Workflow

Multiple sessions

…we’ll get to that.

Page 6: Tmux Development Workflow

Hierarchy

• Sessions contain windows• Windows contain panes• Panes contain your junk

Sessions > Windows > Panes

Page 7: Tmux Development Workflow

More familiarly…

Page 8: Tmux Development Workflow

Benefits• Available anywhere• Terminal independent• Highly customisable• Sessions are awesome (…we’ll still get to

that)• Integrates well with vim (or emacs, I guess)

Page 9: Tmux Development Workflow

Getting started

Page 10: Tmux Development Workflow

Install tmux

$ brew install tmux # OS X

$ sudo pacman -S tmux # Arch

$ sudo apt-get install tmux # Debian

$ apt-cyg install tmux # FML

Page 11: Tmux Development Workflow

Use tmux

$ tmux # dumps you into a new session

# or, to give your new session a name:

$ tmux new -s foo

Page 12: Tmux Development Workflow

Basics

• Interact with commands• Prefix: CTRL+b• Command mode: <prefix> :

Page 13: Tmux Development Workflow

Windows• New window: <prefix> c• Next window: <prefix> n• Previous window: <prefix> p• Go to window by number: <prefix> 0..9• List windows: <prefix> w• Rename window: <prefix> ,

Page 14: Tmux Development Workflow

Panes

• Horizontal split: <prefix> “• Vertical split: <prefix> %• Switch pane: <prefix> ← / → / ↑ / ↓ • Go to pane: <prefix> q

Page 15: Tmux Development Workflow

IntermissionLet’s customise!

Page 16: Tmux Development Workflow

Customising mappings

• You work with windows and panes all the time

• Default key mappings are clunky• tmux makes it easy to change stuff• Config file lives in ~/.tmux.conf

Page 17: Tmux Development Workflow

Starting point• http://tiny.cc/licotmux• Sane defaults (UTF-8, vi-keys, status line)• Easier splits (C-h/j/k/l, M--, M-\) • Easier window navigation (M-j/k)• Easier session navigation (M-8, M-9/0)• Some other junk (but not too much)

Page 18: Tmux Development Workflow

Sessions

• Sessions can run headlessly• Close your terminal (or tab), re-attach later:

tmux attach -t foo• Quickly switch context

Page 19: Tmux Development Workflow

Session persistenceFor those rare crashes and reboots

Page 20: Tmux Development Workflow

Options

• tmuxinatorhttps://github.com/tmuxinator/tmuxinator

• tmux-resurrecthttps://github.com/tmux-plugins/tmux-resurrect

• tmuxifier (not covered)https://github.com/jimeh/tmuxifier

Page 21: Tmux Development Workflow

tmuxinator+ Fine-grained control+ Portable+ Easy to copy to a similar project- Awkward to write- Awkward to change

Page 22: Tmux Development Workflow

tmux-resurrect+ Nothing to write+ Quick & easy to use+ Restores vim sessions+ I prefer it, so you should too!- Not as portable- Can’t copy settings from context to context

Page 23: Tmux Development Workflow

tmux-resurrect installation

• Install TPM, the tmux plugin managerhttps://github.com/tmux-plugins/tpm

• Install tmux-resurrect as a pluginhttps://github.com/tmux-plugins/tmux-resurrect

• Just RTFMs.

Page 24: Tmux Development Workflow

tmux-resurrect usage1. Do stuff

2. <prefix> <C-s> # save

3. … PC crashes …

4. Start tmux

5. <prefix> <C-r> # restore

6. Smile :-)

Page 25: Tmux Development Workflow

Vim integration

Page 26: Tmux Development Workflow

Splits & panes

• Install christoomey/vim-tmux-navigatorhttps://github.com/christoomey/vim-tmux-navigator

• Move between vim splits and tmux panes with C-h/j/k/l.

Page 27: Tmux Development Workflow

Send command to pane

• Install benmills/vimuxhttps://github.com/benmills/vimux

• :VimuxRunCommand “foo”• Check out the GitHub page for related

plugins.

Page 28: Tmux Development Workflow

Run specs in pane• Install thoughtbot/vim-rspec

https://github.com/thoughtbot/vim-rspec

• let g:rspec_command = '

\call VimuxRunCommand(

\"clear && bundle exec rspec {spec}")'

• :call RunNearestSpec()

Page 29: Tmux Development Workflow

You gotta map this stuff

nnoremap <leader>sf :call RunCurrentSpecFile()<CR>

nnoremap <leader>ss :call RunNearestSpec()<CR>

nnoremap <leader>sl :call RunLastSpec()<CR>

nnoremap <leader>sa :call RunAllSpecs()<CR>

Page 30: Tmux Development Workflow

I think that’s about it.

Page 31: Tmux Development Workflow

Other stufftmux-continuumAutomates restoring tmux-resurrect sessionshttps://github.com/tmux-plugins/tpm

tmux-cheatsheetGreat list of mappings. Also try <prefix> ?https://gist.github.com/MohamedAlaa/2961058

Consider remapping prefixWhat if you’re running tmux over ssh in tmux?

Slideshttp://www.slideshare.net/jschembri/tmux-development-workflow