tmux scripts

2026-03-13T09:09:13-0400 | 368 words

I keep public dotfiles which, as far as I know, only one person watches besides me, but I try to temper myself there in all the evils and silliness I really use Linux for. Here are two scripts I would not put on my Codeberg profile, both involving tmux and both using Bash declarative arrays.

mux

#!/usr/bin/env bash
set -euo pipefail
shopt -s extglob

declare -A SESSIONS=(
  [note]="$HOME/d/flor"
  [dots]="$HOME/p/dots"
  [meow]="$HOME/p/www/nekoweb"
  [page]="$HOME/p/www/pages"
)

SESSION="${1:-}"

if [[ -z "$SESSION" ]]; then
  echo "usage: t <session>" >&2
  echo "known: ${!SESSIONS[*]}" >&2
  exit 1
fi

if [[ -z "${SESSIONS[$SESSION]+_}" ]]; then
  echo "known session: '$SESSION'" >&2
  echo "known: ${!SESSIONS[*]}" >&2
  exit 1
fi

START_DIR="${SESSIONS[$SESSION]}"

if tmux has-session -t "$SESSION" 2>/dev/null; then
  tmux attach-session -t "$SESSION"
else
  tmux new-session -s "$SESSION" -c "$START_DIR"
fi

The array is near-daily projects, including this website and my more professional open source devblog. Normally if you run tmux new -s <preexisting session> it complains, so this just runs tmux has-session for me and attaches it if it exists or creates it if not. While I use Sway and could tile or hide terminals, I find I prefer tmux if one of those terminals is just a watchdog.

anime

#!/usr/bin/env bash
set -euo pipefail

SERVER="goingmerry"
MOUNTPOINT="$HOME/v/merry"
SCREENSHOT_DIR="$HOME/m/img/cap"

declare -A MOUNTS=(
  [booty]="$SERVER:/mnt/booty/vid mpv"
  [mago]="$SERVER:m/vid/mago hawkins"
)

if ! tailscale ping --timeout=2s --c=1 "$SERVER" &>/dev/null; then
  echo "$SERVER is offline"
  exit 1
fi

echo "$SERVER is online"

target="${1:-}"
entry="${MOUNTS[$target]:-}"

if [[ -z "$entry" ]]; then
  echo "usage: ./merrygo ($(
    IFS='|'
    echo "${!MOUNTS[*]}"
  ))"
  exit 1
fi

remote="${entry%% *}"
session="${entry##* }"

sshfs "$remote" "$MOUNTPOINT"
tmux new-session -d -s "$session" -c "$MOUNTPOINT"
tmux send-keys -t "$session" "tmux new-window -c $SCREENSHOT_DIR" Enter
tmux attach -t "$session"

And here's my most fun use of tmux and Tailscale. My devbox has only 128G flash storage, so I leave my external 2T drive attached to my ancient desktop and mount it on boot with fstab. The only two mountpoints I've specified are the 2T drive /mnt/booty and the directory in my user's $HOME of every Basil Hawkins episode. I have each tmux session attach at my screenshot directory so I can go wild and know they're saved to my laptop.