#!/usr/bin/env bash
# bin/morning — set up the tmux windows and browser tabs I start every day with.
# Idempotent: if the session already exists, it just reattaches.
set -euo pipefail
SESSION="${MORNING_SESSION:-main}"
CODE_ROOT="${CODE_ROOT:-$HOME/code}"
NOTES_ROOT="${NOTES_ROOT:-$HOME/notes}"
# 1) Browser tabs: open once if no tab with that URL is already open.
# Using `open -g` to avoid stealing focus on macOS.
MORNING_TABS=(
"https://github.com/pulls/assigned"
"https://github.com/pulls/review-requested"
"https://cal.google.com"
)
if [[ "${MORNING_OPEN_TABS:-1}" == "1" && "$OSTYPE" == darwin* ]]; then
for url in "${MORNING_TABS[@]}"; do
open -g "$url" || true
done
fi
# 2) tmux session with three windows: notes, main repo, scratch.
if tmux has-session -t "$SESSION" 2>/dev/null; then
exec tmux attach -t "$SESSION"
fi
nb >/dev/null 2>&1 || true # ensure today's note exists
tmux new-session -d -s "$SESSION" -n notes -c "$NOTES_ROOT"
tmux send-keys -t "$SESSION:notes" "nb" C-m
main_repo="${MORNING_REPO:-$CODE_ROOT/github.com/$(whoami)/dotfiles}"
if [[ -d "$main_repo" ]]; then
tmux new-window -t "$SESSION" -n dev -c "$main_repo"
tmux send-keys -t "$SESSION:dev" "git fetch --prune" C-m
else
tmux new-window -t "$SESSION" -n dev -c "$HOME"
fi
tmux new-window -t "$SESSION" -n scratch -c "$HOME"
tmux select-window -t "$SESSION:notes"
exec tmux attach -t "$SESSION"