DEV Community

Alexis Reigel
Alexis Reigel

Posted on

Easy tmux session setup

Original post:

www.koffeinfrei.org/2021/08/14/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
Enter fullscreen mode Exit fullscreen mode

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

screen

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

  • new-window: Create a new window
  • split-window -h: Create a horizontal split pane
  • split-window -v: Create a vertical split pane
  • send-keys: Execute a command, i.e. start a program

Top comments (3)

Collapse
 
fenix profile image
Fenix

KISS one. yay! ... i'm gonna use it as starting point for my setup. Thanks, thanks, thanks

Collapse
 
horaciodegiorgi profile image
Horacio Degiorgi

thanks , very clear.
the alias watch-status
is for "watch git status -s" ?

Collapse
 
koffeinfrei profile image
Alexis Reigel • Edited

the alias watch-status is for "watch git status -s" ?

Yes:

watch --color --interval 1 --no-title git -c color.status=always status -bs
Enter fullscreen mode Exit fullscreen mode

github.com/koffeinfrei/dotfiles/bl...