Sunday, September 04, 2022

Share your tmux tricks

This is my ~/bin/bootstrap-tmux script.

Maybe it can inspire you to share some of your tmux config snippets or
tricks? I'd also be interested if you have suggestions for improvements
to my script.


#!/bin/sh
#
# Bootstraps tmux to 80%; saves a bit of typing and thinking right after
# reboots when I just want to get back to work.

set -e

# If I specify ~/work it messes up the tmux config, so cd to home first
cd $HOME
WORKDIR="projects/* business/. work wrk 3rdparty/*"

# Build tmux sessions and windows based on the my project directories. These
# almost always reflect what I am working on anyway.
for wpath in $WORKDIR; do
if [ -d $wpath ]; then
session_name=$(dirname $wpath | sed 's/\./_/g')
wname=$(basename $wpath)
if $(tmux has-session -t $session_name); then
tmux new-window -d -t $session_name -c $wpath -n $wname
else
tmux new-session -P -d -s $session_name -c $wpath -n $wname
fi
# Populate the session with windows, etc per project
if [ -f $wpath/.tmux.conf.local ]; then
tmux source-file $wpath/.tmux.conf.local
fi
fi
done

if [ -d ~/Business/Mail -o -d ~/Personal/Mail ]; then
tmux new-session -P -d -s email -n neomutt neomutt
fi

WORKDIR="/usr/src /usr/ports /usr/ports/mystuff /usr/xenocara"

for wpath in $WORKDIR; do
# Are there signs of a usable OpenBSD src checkout?
if [ -w $wpath/Makefile ]; then
wname=$(basename $wpath)
if $(tmux has-session -t openbsd); then
tmux new-window -P -d -t openbsd -c $wpath -n $wname
else
tmux new-session -P -d -s openbsd -c $wpath -n $wname
fi
# Populate the session with windows, etc per project
if [ -f $wpath/.tmux.conf.local ]; then
tmux source-file $wpath/.tmux.conf.local
fi
fi
done

No comments:

Post a Comment