Workflow 002: Multi-Project Setup
FreshManage multiple projects simultaneously using tmux sessions and windows.
When to Use
- Working on multiple projects daily
- Need quick context switching
- Want isolated environments per project
- Managing microservices or monorepos
Strategy Overview
Setup
Project Session Script
Create ~/bin/proj (make executable with chmod +x):
bash
#!/bin/bash
# Usage: proj <project-name> [project-path]
PROJECT=$1
PROJECT_PATH=${2:-"$HOME/projects/$PROJECT"}
if [ -z "$PROJECT" ]; then
echo "Usage: proj <project-name> [project-path]"
exit 1
fi
# Check if session exists
tmux has-session -t "$PROJECT" 2>/dev/null
if [ $? != 0 ]; then
# Create new session
tmux new-session -d -s "$PROJECT" -n editor -c "$PROJECT_PATH"
# Editor window (already created)
tmux send-keys -t "$PROJECT:editor" 'vim .' C-m
# Server window
tmux new-window -t "$PROJECT" -n server -c "$PROJECT_PATH"
# Tests window
tmux new-window -t "$PROJECT" -n tests -c "$PROJECT_PATH"
# Git window
tmux new-window -t "$PROJECT" -n git -c "$PROJECT_PATH"
tmux send-keys -t "$PROJECT:git" 'git status' C-m
# Select editor window
tmux select-window -t "$PROJECT:editor"
fi
# Attach to session
tmux attach -t "$PROJECT"Framework-Specific Setups
Node.js Project
bash
#!/bin/bash
PROJECT="myapp"
PROJECT_PATH="$HOME/projects/$PROJECT"
tmux new-session -d -s "$PROJECT" -n code -c "$PROJECT_PATH"
# Code window with split
tmux send-keys -t "$PROJECT:code" 'vim .' C-m
tmux split-window -h -t "$PROJECT:code" -c "$PROJECT_PATH"
tmux send-keys -t "$PROJECT:code.1" 'npm run dev' C-m
# Tests window
tmux new-window -t "$PROJECT" -n tests -c "$PROJECT_PATH"
tmux send-keys -t "$PROJECT:tests" 'npm test -- --watch' C-m
# Logs window
tmux new-window -t "$PROJECT" -n logs -c "$PROJECT_PATH"
tmux select-window -t "$PROJECT:code"
tmux attach -t "$PROJECT"Python Project
bash
#!/bin/bash
PROJECT="pyapp"
PROJECT_PATH="$HOME/projects/$PROJECT"
VENV_PATH="$PROJECT_PATH/venv"
tmux new-session -d -s "$PROJECT" -n code -c "$PROJECT_PATH"
# Activate venv in all windows
ACTIVATE="source $VENV_PATH/bin/activate"
# Code window
tmux send-keys -t "$PROJECT:code" "$ACTIVATE && vim ." C-m
# Server window
tmux new-window -t "$PROJECT" -n server -c "$PROJECT_PATH"
tmux send-keys -t "$PROJECT:server" "$ACTIVATE && python manage.py runserver" C-m
# Shell window
tmux new-window -t "$PROJECT" -n shell -c "$PROJECT_PATH"
tmux send-keys -t "$PROJECT:shell" "$ACTIVATE" C-m
# Tests
tmux new-window -t "$PROJECT" -n tests -c "$PROJECT_PATH"
tmux send-keys -t "$PROJECT:tests" "$ACTIVATE && pytest --watch" C-m
tmux select-window -t "$PROJECT:code"
tmux attach -t "$PROJECT"Daily Workflow
Start of Day
bash
# Open all project sessions
proj frontend ~/code/frontend
# Detach: Ctrl+b d
proj backend ~/code/backend
# Detach: Ctrl+b d
proj devops ~/code/infra
# Stay attached or detachSwitching Projects
bash
# From within tmux, show session list
Ctrl+b s
# Navigate with arrows, Enter to switch
# Or use shortcuts:
Ctrl+b ( # Previous session
Ctrl+b ) # Next sessionContext-Aware Windows
Navigate windows:
bash
Ctrl+b w # Window list across all sessions
Ctrl+b n # Next window in session
Ctrl+b p # Previous window
Ctrl+b 1-9 # Jump to window numberMicroservices Layout
For microservices, use one session with service-per-window:
bash
#!/bin/bash
SESSION="microservices"
BASE="$HOME/projects/microservices"
tmux new-session -d -s $SESSION -n overview
# Service windows
for service in auth users orders payments notifications; do
tmux new-window -t $SESSION -n $service -c "$BASE/$service"
tmux send-keys -t "$SESSION:$service" "docker-compose up" C-m
done
# Monitoring window
tmux new-window -t $SESSION -n monitor
tmux send-keys -t "$SESSION:monitor" "docker ps --format 'table {{.Names}}\t{{.Status}}' -a" C-m
tmux select-window -t $SESSION:overview
tmux attach -t $SESSIONMonorepo Layout
bash
#!/bin/bash
SESSION="monorepo"
BASE="$HOME/projects/monorepo"
tmux new-session -d -s $SESSION -n root -c "$BASE"
# Package windows
tmux new-window -t $SESSION -n web -c "$BASE/packages/web"
tmux new-window -t $SESSION -n api -c "$BASE/packages/api"
tmux new-window -t $SESSION -n shared -c "$BASE/packages/shared"
# Development window with all services
tmux new-window -t $SESSION -n dev -c "$BASE"
tmux send-keys -t "$SESSION:dev" "npm run dev" C-m
tmux select-window -t $SESSION:root
tmux attach -t $SESSIONSession Management Commands
bash
# List all sessions
tmux ls
# Kill specific session
tmux kill-session -t frontend
# Kill all sessions except current
tmux kill-session -a
# Rename session
Ctrl+b $
# Create new session from within tmux
:new -s newprojectTips
Quick Session Aliases
Add to ~/.bashrc or ~/.zshrc:
bash
alias pf='proj frontend'
alias pb='proj backend'
alias pd='proj devops'
alias tls='tmux ls'
alias ta='tmux attach -t'Session Naming Convention
Use consistent naming:
project-namefor main workproject-name-featurefor feature branchesscratchfor temporary work
Window Naming Convention
Consistent window names across projects:
editor- Main code editingserver- Running dev servertests- Test runnergit- Version controlshell- General terminal
Troubleshooting
Too many sessions
bash
# List and review
tmux ls
# Kill unused ones
tmux kill-session -t old-projectForgot which session has what
bash
# Preview sessions and windows
Ctrl+b s # Expand with arrow keysNeed to move window between sessions
bash
:move-window -s source-session:window -t target-session: