wait-for-event.sh 628 B

1234567891011121314151617181920
  1. #!/bin/bash
  2. # Wait for a browser event from the brainstorm server
  3. # Usage: wait-for-event.sh <output-file> [event-type]
  4. #
  5. # Blocks until a matching event arrives, then prints it and exits.
  6. # Default event type: "send-to-claude"
  7. OUTPUT_FILE="${1:?Usage: wait-for-event.sh <output-file> [event-type]}"
  8. EVENT_TYPE="${2:-send-to-claude}"
  9. if [[ ! -f "$OUTPUT_FILE" ]]; then
  10. echo "Error: Output file not found: $OUTPUT_FILE" >&2
  11. exit 1
  12. fi
  13. # Wait for new lines matching the event type
  14. # -n 0: start at end (only new content)
  15. # -f: follow
  16. # grep -m 1: exit after first match
  17. tail -n 0 -f "$OUTPUT_FILE" | grep -m 1 "$EVENT_TYPE"