Homepage
free software, web technologies and heavy metal coding (and ruby of course)

Easy tmux session setup

For development I need a certain tmux setup, which I don’t want to kick off every time manually. I used to use Tmuxinator to manage my tmux session setup. For mainly two reasons I switched away from it though. To be clear, none of them are the tools’ fault.

  1. I don’t need a per project setup
  2. My setup is fairly simple, which doesn’t really justify the dependency

What I now have is a bash script that sets up my tmux session with all the windows and split panes bootstrapped and tools running that I usually need. Since my setup isn’t very complicated using tmux commands is enough and I don’t need the declarative yaml structure that Tmuxinator provides.

This is my annotated tmux-dev script:

#!/usr/bin/env bash

# Create a tmux session
tmux new-session -d

# Start vim in the first window
tmux send-keys 'vim' C-m

# Create a 2nd window
tmux new-window

# Create a horizontal split in the 2nd window, with 75% / 25% width distribution
tmux split-window -h -p 25

# Start `git watch-status` in the right split
tmux send-keys 'git watch-status' C-m

# Split the right split vertically
tmux split-window -v

# Start `git watch-log` in the right bottom split
tmux send-keys 'git watch-log' C-m

# Focus the left split pane
tmux select-pane -t 0

# Create a 3rd window, without running a command
tmux new-window

# Go to the 1st window (vim) and put the focus on it
tmux select-window -t 0
tmux select-pane -t 0

# Attach the session. Ready to start hacking
tmux -2 attach-session -d

This is what the tmux session from the above script looks like:

The most important commands to define the setup are the following: