| Philip Zeyliger | 7b60449 | 2025-04-29 11:45:59 -0700 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # This script lists all currently running sketch containers in Docker, |
| 4 | # displaying their container names, local URLs, and sketch titles. |
| 5 | # It extracts port mappings and queries each sketch's state endpoint |
| 6 | # to provide a convenient overview of running sketches. |
| 7 | |
| 8 | docker ps --format "{{.Names}}|{{.Ports}}" | \ |
| 9 | grep sketch | \ |
| 10 | sed -E 's/.*0\.0\.0\.0:([0-9]+)->80.*/\1/' | \ |
| 11 | while read port; do |
| 12 | # Get container name for this port |
| 13 | name=$(docker ps --filter "publish=$port" --format "{{.Names}}") |
| 14 | |
| 15 | # Get sketch title from its state endpoint |
| 16 | title=$(curl -s "http://localhost:$port/state" | jq -r '.title // "N/A"') |
| 17 | |
| 18 | # Format and print the result |
| 19 | printf "%-30s http://localhost:%d/ %s\n" "$name" "$port" "$title" |
| 20 | done |