blob: 5cfca2a3c0aa53901b64f88a6d5d48e0e285654f [file] [log] [blame]
Philip Zeyliger7b604492025-04-29 11:45:59 -07001#!/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
8docker 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
Philip Zeyliger95594bb2025-06-16 08:57:21 -070016 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 Zeyliger7b604492025-04-29 11:45:59 -070018
19 # Format and print the result
Philip Zeyliger95594bb2025-06-16 08:57:21 -070020 printf "%-30s http://localhost:%d/ %s %s\n" "$name" "$port" "$title" "$message_count"
Philip Zeyliger7b604492025-04-29 11:45:59 -070021 done