Eric Radman : a Journal

TMUX Automation

The first brilliant design feature of tmux is that all of the commands available using C-b : are also available from the command line. The second great design feature is that all of these same commands can be run against a session that is not even connected. The following starts a new session called "harvest" (disconnected) and renames the initial window to "editor":

tmux new-session -s harvest -d
tmux rename-window -t harvest "editor"

With only knowledge of a few tmux commands it is not possible to script a development environment. Here we'll create a new window and start an application that will automatically be reloaded if files change:

tmux new-window -t harvest:1 -n "server"
tmux send-keys -t harvest:1 "ls *.rb | entr -r ruby main.rb" C-m

Other useful operations include split-window and select-pane. After setting all of the workspaces you can switch to first window and attach to session.

tmux select-window -t harvest:0
tmux -2 attach-session -t harvest

To get rid of the entire session use

tmux kill-session -t harvest

Last updated on June 10, 2015