tmuxinator: Save tmux pane and window layouts
While using tmux daily makes your life easier and more colorful you have to admit that creating your default working environment sucks. At least if you use windows and panes. CTRL+V CTRL+H CTRL++ CTRL+- galore
Stop growing grey hair over it, Tmuxiantor is here to help you.
The installation is thanks to RubyGems easy as pie
tmuxinator installation1
$ gem install tmuxinator
Now for some sample configuration,
create a new layout1
$ tmuxinator new daily
will open your default $Editor with a sample config daily.yml
# ~/.tmuxinator/daily.yml
name: daily
root: ~/
# Optional tmux socket
# socket_name: foo
# Runs before everything. Use it to start daemons etc.
# pre: sudo /etc/rc.d/mysqld start
# Runs in each window and pane before window/pane specific commands. Useful for setting up interpreter versions.
pre_window: rbenv shell 2.0.0-p247
# Pass command line options to tmux. Useful for specifying a different tmux.conf.
# tmux_options: -f ~/.tmux.mac.conf
# Change the command to call tmux. This can be used by derivatives/wrappers like byobu.
# tmux_command: byobu
windows:
- editor:
layout: main-vertical
panes:
- vim
- guard
- server: bundle exec rails s
- logs: tail -f logs/development.log
The first indentation create windows, the second sets options and panes. The interesting part is the layout options, either use the tmux default or use your own.
Sure you want your own, or? Open a shell and execute tmux list-windows or call it via the tmux prompt.
fabian@heartofgold ~ tmux list-windows
1: ~* (4 panes) [208x59] [layout 3682,208x59,0,0[208x29,0,0{95x29,0,0,0,112x29,96,0[112x22,96,0,1,112x6,96,23,2]},208x29,0,30,3]] @0 (active)
Copy the highlighted part from your output:
1: ~* (4 panes) [208x59] [layout 3682,208x59,0,0[208x29,0,0{95x29,0,0,0,112x29,96,0[112x22,96,0,1,112x6,96,23,2]},208x29,0,30,3]] @0 (active)
and use it as layout option in your tmuxinator config:
daily.yml
windows:
- local:
layout: 3682,208x59,0,0[208x29,0,0{95x29,0,0,0,112x29,96,0[112x22,96,0,1,112x6,96,23,2]},208x29,0,30,3]
panes:
- weechat
- multitail /var/log/system.log
- watch -n1 'ping -c1 hetzner.de | grep avg'
- date
Before you start make sure to add the following lines to your tmux.conf or tmuxinator won’t be able to locate panes and windows and therefore not start any programs for you.
.tmux.conf
# start window numbering at 1
set -g base-index 1
# start pane numbering at 1
set -g pane-base-index 1
From now don’t start tmux directly, use $ tmuxinator daily
or even shorter $ mux daily
to load tmux and your saved layout.
Below another example, my octopress tmuxinator setup that I use right now to write this lines.
octopress.yml
# ~/.tmuxinator/octopress.yml
name: octopress
root: ~/octopress/
pre_window: rbenv shell 1.9.3-p194
windows:
- editor:
layout: eb15,156x49,0,0{80x49,0,0,11,75x49,81,0[75x36,81,0,12,75x12,81,37,13]}
panes:
- vim
-
- rake watch
# no need for rake preview, since I use pow.cx
Update:
Thanks to Theodoros Ploumis for mentioning Teamocil. Unfortunately his comment has left this blog because of a stupid configuration error (Protip: Know and check your own discus shortnames..).