title: Bash scripts with tmux to launch a 4-paned window
body: <p>Can anyone help explain what's going on with <code>tmux</code>, <code>bash</code>, and <code>exec</code>? I'm trying to set up a tmux session with a 4-pane window. Ideally, I want to run a command in 3 of the panes: e.g. a Ruby Thin server and a couple of Ruby daemons. This is what I have so far:</p>
  
  <p><code>~/.bin/tmux-foo</code>:</p>
  
  <pre><code>#!/bin/sh
  
  tmux new-session -d -s foo 'exec pfoo "bundle exec thin start"'
  tmux rename-window 'Foo'
  tmux select-window -t foo:0
  tmux split-window -h 'exec pfoo "bundle exec compass watch"'
  tmux split-window -v -t 0 'exec pfoo "rake ts:start"'
  tmux split-window -v -t 1 'exec pfoo'
  tmux -2 attach-session -t foo
  </code></pre>
  
  <p><code>~/.bin/pfoo</code>:</p>
  
  <pre><code>#!/bin/bash
  cd ~/projects/foo
  rvm use ree
  
  # here I want to execute command1 2 3 or 4...
  
  exec $SHELL
  </code></pre>
  
  <p>It all works... but when I <code>ctlr-c</code> in the first pane that is running the thin server, it stops the thin server and returns to the shell. However, the command is not in the history; i.e. if I hit the up key I don't get the <code>bundle exec thin start</code> command... I get some other command from my bash history. I'm wondering if there's any way to arrange these scripts so that I get the commands in the bash history.</p>
  
  <p>Also... I've tried many combinations of <code>exec</code>, <code>exec $SHELL -s ...</code>, and <code>exec $SHELL -s ... -I</code> and I'm not quite sure what is going on...</p>
  
  <p>Can anyone help explain the general idea of what is going on with <code>tmux</code> and <code>bash</code> and <code>exec</code> here?</p>