● กำลังพัฒนา
Dev Session Starter
Script และ tmux config สำหรับเปิด development environment ด้วยคำสั่งเดียว — sessions, panes, และ services ขึ้นมาพร้อมทำงานทันที
สารบัญ
ปัญหาที่แก้
ทุกเช้าหรือหลังเครื่อง restart ต้องเปิด terminal ใหม่, ไป directory โปรเจกต์, เปิด session แยก, รัน dev server, เปิด editor — ซ้ำทุกวัน
Dev Session Starter แก้ปัญหานี้ด้วย shell script เดียวที่ทำทุกอย่างให้
ฟีเจอร์
- สร้าง tmux session ตามชื่อโปรเจกต์อัตโนมัติ
- แบ่ง panes: editor | terminal | dev server | log
- cd ไป working directory ที่กำหนด
- รัน
npm run devใน pane ที่กำหนด - attach session ถ้ามีอยู่แล้ว ไม่ซ้ำซ้อน
ตัวอย่าง config
# ~/.dev-sessions/panupong-creative-space.sh
SESSION="panupong"
DIR="$HOME/panupong-creative-space"
# ถ้า session มีอยู่แล้ว attach เลย
if tmux has-session -t "$SESSION" 2>/dev/null; then
tmux attach-session -t "$SESSION"
exit 0
fi
# สร้าง session ใหม่
tmux new-session -d -s "$SESSION" -c "$DIR" -x 220 -y 50
# window 1: editor
tmux rename-window -t "$SESSION:1" "code"
tmux send-keys -t "$SESSION:code" "nvim ." Enter
# window 2: dev server
tmux new-window -t "$SESSION" -n "dev" -c "$DIR"
tmux send-keys -t "$SESSION:dev" "npm run dev" Enter
# window 3: terminal
tmux new-window -t "$SESSION" -n "term" -c "$DIR"
# attach
tmux attach-session -t "$SESSION"
วิธีใช้
chmod +x ~/.dev-sessions/panupong-creative-space.sh
# เพิ่มใน .bashrc หรือ .zshrc
alias pcs="~/.dev-sessions/panupong-creative-space.sh"
# เปิดด้วย
pcs
tmux.conf ที่ใช้ร่วมกัน
# mouse support
set -g mouse on
# start index จาก 1
set -g base-index 1
setw -g pane-base-index 1
# status bar
set -g status-style bg=default,fg=colour250
set -g window-status-current-style fg=colour39,bold
เหตุผลที่ทำ
ผมทำงานบน WSL2 + tmux ทุกวัน และมักมีหลายโปรเจกต์พร้อมกัน script นี้ลด friction ในการเริ่มงานใหม่แต่ละวันลงมาก