| 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 | \ |
| Philip Zeyliger | d5f0a3e | 2025-06-30 09:38:21 -0700 | [diff] [blame] | 10 | sed -n -E 's/.*0\.0\.0\.0:([0-9]+)->80.*/\1/p' | \ |
| Philip Zeyliger | 7b60449 | 2025-04-29 11:45:59 -0700 | [diff] [blame] | 11 | while read port; do |
| 12 | # Get container name for this port |
| 13 | name=$(docker ps --filter "publish=$port" --format "{{.Names}}") |
| Philip Zeyliger | d5f0a3e | 2025-06-30 09:38:21 -0700 | [diff] [blame] | 14 | |
| Philip Zeyliger | 7b60449 | 2025-04-29 11:45:59 -0700 | [diff] [blame] | 15 | # Get sketch title from its state endpoint |
| Philip Zeyliger | 95594bb | 2025-06-16 08:57:21 -0700 | [diff] [blame] | 16 | title=$(curl --connect-timeout 1 -s "http://localhost:$port/state" | jq -r '.slug // "N/A"') |
| 17 | message_count=$(curl --connect-timeout 1 -s "http://localhost:$port/state" | jq -r '.message_count // "N/A"') |
| Philip Zeyliger | d5f0a3e | 2025-06-30 09:38:21 -0700 | [diff] [blame] | 18 | |
| Philip Zeyliger | 7b60449 | 2025-04-29 11:45:59 -0700 | [diff] [blame] | 19 | # Format and print the result |
| Philip Zeyliger | 95594bb | 2025-06-16 08:57:21 -0700 | [diff] [blame] | 20 | printf "%-30s http://localhost:%d/ %s %s\n" "$name" "$port" "$title" "$message_count" |
| Philip Zeyliger | 7b60449 | 2025-04-29 11:45:59 -0700 | [diff] [blame] | 21 | done |