Quick tmux dev setup
published: 2024-11-30
tags:
bash
tmux
I use a tiling window manager and have done for a very long time but I've alternated between using tmux
and simply opening more terminals many times. I can never really decide which I prefer, though there is something nice about essentially having a another contained tiler for each project 🤔
Anyway, that's a thought for another time. I'm currently on my "using tmux" stint and it's occurred to me that I always open every project the same way way and should probably just automate that. I primarily use go
and I use fossil
as my version control, so I've written a small script that uses rofi
to launch my usual environment.
The script starts by listing the names of each of my project folders in rofi
then creating a new tmux
session with the same name. Next, it creates two windows, the first running vim
and the second gets vertically split. On the left pane of the second window it runs fossil changes
to show me the files I have uncommitted changes in and the right because whenever I do go to commit changes I usually have a diff on one while I write a message, maybe running the program and need to use commands while looking at it's output or similar.
The script
#!/usr/bin/env bash
# Launch rofi with a list from the projects directory
projectsDir="~/projects/programming/go"
project=$(ls -1 ~/projects/programming/go | rofi -dmenu -p "project")
# Exit if no project was selected
if [[ -z "$project" ]]; then
exit
fi
# Create new session and name the window according to the project name
tmux new -s $project -d
tmux rename-window -t $project vim
# Change to the project directory and open vim
tmux send-keys -t $project "cd $projectsDir/$project" C-m
tmux send-keys -t $project C-l
tmux send-keys -t $project "vim" C-m
# Make a new window in the project directory and run 'fossil changes'
tmux new-window -t $project
tmux select-window -t $project:1
tmux rename-window -t $project bash
tmux send-keys -t $project "cd $projectsDir/$project" C-m
tmux send-keys -t $project C-l
tmux send-keys -t $project "fossil changes" C-m
# Split the window
tmux split-window -h -t $project
tmux send-keys -t $project "cd $projectsDir/$project" C-m
tmux send-keys -t $project C-l
# Select the fossil changes pane
tmux select-pane -L -t $project
# Open a terminal and attach the session
alacritty -e tmux attach -d -t $project