Tmux Development Workflow
-
Upload
jschembri -
Category
Technology
-
view
349 -
download
0
Transcript of Tmux Development Workflow
TMUXDevelopment workflow
What does it do?
Multiple panes
Multiple windows
Multiple sessions
…we’ll get to that.
Hierarchy
• Sessions contain windows• Windows contain panes• Panes contain your junk
Sessions > Windows > Panes
More familiarly…
Benefits• Available anywhere• Terminal independent• Highly customisable• Sessions are awesome (…we’ll still get to
that)• Integrates well with vim (or emacs, I guess)
Getting started
Install tmux
$ brew install tmux # OS X
$ sudo pacman -S tmux # Arch
$ sudo apt-get install tmux # Debian
$ apt-cyg install tmux # FML
Use tmux
$ tmux # dumps you into a new session
# or, to give your new session a name:
$ tmux new -s foo
Basics
• Interact with commands• Prefix: CTRL+b• Command mode: <prefix> :
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> ,
Panes
• Horizontal split: <prefix> “• Vertical split: <prefix> %• Switch pane: <prefix> ← / → / ↑ / ↓ • Go to pane: <prefix> q
IntermissionLet’s customise!
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
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)
Sessions
• Sessions can run headlessly• Close your terminal (or tab), re-attach later:
tmux attach -t foo• Quickly switch context
Session persistenceFor those rare crashes and reboots
Options
• tmuxinatorhttps://github.com/tmuxinator/tmuxinator
• tmux-resurrecthttps://github.com/tmux-plugins/tmux-resurrect
• tmuxifier (not covered)https://github.com/jimeh/tmuxifier
tmuxinator+ Fine-grained control+ Portable+ Easy to copy to a similar project- Awkward to write- Awkward to change
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
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.
tmux-resurrect usage1. Do stuff
2. <prefix> <C-s> # save
3. … PC crashes …
4. Start tmux
5. <prefix> <C-r> # restore
6. Smile :-)
Vim integration
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.
Send command to pane
• Install benmills/vimuxhttps://github.com/benmills/vimux
• :VimuxRunCommand “foo”• Check out the GitHub page for related
plugins.
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()
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>
I think that’s about it.
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