#!/bin/bash
# Start pear-git in tmux session (following pear-seed pattern)
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
SESSION="pear-seed"
WINDOW="pear-git"
# Check if pear-seed session exists
if ! tmux has-session -t "$SESSION" 2>/dev/null; then
echo "Creating tmux session: $SESSION"
tmux new-session -d -s "$SESSION" -n "$WINDOW"
else
# Check if pear-git window already exists
if tmux list-windows -t "$SESSION" | grep -q "$WINDOW"; then
echo "❌ pear-git window already exists in $SESSION session"
echo " Use ./scripts/pear-git-stop.sh first"
exit 1
fi
# Create new window in existing session
tmux new-window -t "$SESSION" -n "$WINDOW"
fi
echo "✓ Created tmux window: $SESSION:$WINDOW"
echo ""
# Start pear-git server in tmux window
echo "Starting pear-git server..."
tmux send-keys -t "$SESSION:$WINDOW" "cd $PROJECT_DIR" C-m
tmux send-keys -t "$SESSION:$WINDOW" "./scripts/run-loop.sh web 5005 --vpn --prefix=/git" C-m
echo "✓ pear-git server started"
echo ""
echo "📡 Access:"
echo " Local: http://localhost:5005/git/"
echo " VPN: http://10.22.0.1:5005/git/"
echo " Public: https://7rnx.net/git/"
echo ""
echo "📋 Tmux commands:"
echo " Attach: tmux attach -t $SESSION"
echo " Switch: Ctrl+B, then type: select-window -t $WINDOW"
echo " Detach: Ctrl+B, then D"
echo ""
echo "🛑 Stop:"
echo " ./scripts/pear-git-stop.sh"