#!/bin/bash # Configuration SESSION_NAME="web_dev" FE_PATH="/path/to/your/frontend" BE_PATH="/path/to/your/backend" DB_PATH="/path/to/your/database" # Or just specify DB commands # Check if tmux is installed if ! command -v tmux &> /dev/null; then echo "Error: tmux is not installed. Please install it to use this script." exit 1 fi # Function to start a tmux session and panes start_dev_services() { echo "Starting development services in tmux session: $SESSION_NAME" # Create a new detached tmux session tmux new-session -d -s "$SESSION_NAME" # Create panes and run commands # Frontend Dev Server tmux send-keys -t "$SESSION_NAME" "cd $FE_PATH && npm run dev" C-m tmux rename-window -t "$SESSION_NAME:0" "frontend" # Backend API Server tmux new-window -t "$SESSION_NAME" -n "backend" tmux send-keys -t "$SESSION_NAME:backend" "cd $BE_PATH && npm run start:dev" C-m # Example Node.js/NestJS # Or for Python/Django/Flask: "cd $BE_PATH && python manage.py runserver" C-m # Database (e.g., start a local PostgreSQL or show logs) tmux new-window -t "$SESSION_NAME" -n "database" tmux send-keys -t "$SESSION_NAME:database" "docker-compose -f $DB_PATH/docker-compose.yml up" C-m # Example with Docker Compose # Or just "psql -U youruser -d yourdb" C-m if you want to connect manually # Optional: Another service or just a general terminal tmux new-window -t "$SESSION_NAME" -n "general" tmux send-keys -t "$SESSION_NAME:general" "cd $FE_PATH" C-m echo "Services started. Attach to the tmux session using: tmux attach -t $SESSION_NAME" echo "You can switch windows with Ctrl-b n (next) and Ctrl-b p (previous)." echo "To detach: Ctrl-b d" } # Function to stop/kill the tmux session stop_dev_services() { if tmux has-session -t "$SESSION_NAME" 2>/dev/null; then echo "Stopping development services by killing tmux session: $SESSION_NAME" tmux kill-session -t "$SESSION_NAME" echo "Session '$SESSION_NAME' killed." else echo "No active tmux session named '$SESSION_NAME' found." fi } # Main logic case "$1" in start) start_dev_services ;; stop) stop_dev_services ;; restart) stop_dev_services start_dev_services ;; attach) if tmux has-session -t "$SESSION_NAME" 2>/dev/null; then echo "Attaching to tmux session: $SESSION_NAME" tmux attach -t "$SESSION_NAME" else echo "No active tmux session named '$SESSION_NAME' found. Use 'start' first." fi ;; *) echo "Usage: $0 {start|stop|restart|attach}" exit 1 ;; esac