1

Can anyone help explain what's going on with tmux, bash, and exec? 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:

~/.bin/tmux-foo:

#!/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

~/.bin/pfoo:

#!/bin/bash
cd ~/projects/foo
rvm use ree

# here I want to execute command1 2 3 or 4...

exec $SHELL

It all works... but when I ctlr-c 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 bundle exec thin start 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.

Also... I've tried many combinations of exec, exec $SHELL -s ..., and exec $SHELL -s ... -I and I'm not quite sure what is going on...

Can anyone help explain the general idea of what is going on with tmux and bash and exec here?

2 Answers 2

1

It turns out that I wanted something like this:

tmux splitw -t 'foo':2
tmux send-keys -t 'foo':2 'rvm use ree' C-m
tmux send-keys -t 'foo':2 'bundle exec compass watch

send-keys with C-m will execute the command in the window/pane and will keep it in the history.

0

The commands are not in the shell's history simply because you started the shell after running those commands. Ctrl-C doesn't return to a shell; it causes pfoo to start a new one (the exec $SHELL line).

2
  • Ah... makes sense. Do you know of any way to get the command into the history. Is there a way to exec $SHELL with the command? Mar 27, 2011 at 18:37
  • @Aaron: 1) Append it to the history file (echo "$@" >> ~/.bash_history) before exec'ing. 2) No. Mar 27, 2011 at 18:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .