#!/bin/sh -e

text=$(tmux capture-pane -J -p)

{
  # UUIDs (8-4-4-4-12 format)
  echo "${text}" | grep -Eo '\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b' | sed 's/^/UUID: /'

  # git SHA (7-40 hex chars, avoiding UUIDs)
  echo "${text}" | grep -Eo '\b[0-9a-f]{7,40}\b' | grep -v -- '-' | sed 's/^/SHA: /'

  # URLs
  echo "${text}" | grep -Eo '(https?|ftp|file):/?//[-A-Za-z0-9+&@#/%?=~_|!:,.;]*[-A-Za-z0-9+&@#/%=~_|]' | sed 's/^/URL: /'

  # file paths (specific extensions)
  echo "${text}" | grep -Eo '\b[a-zA-Z0-9_/-\.]*\.(go|py|rs|js|ts|json|yaml|yml|md)\b' \
    | grep -v '^https\?:' | sed 's/^/FILE: /'

  # IP addresses
  echo "${text}" | grep -Eo '\b[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\b' | sed 's/^/IP: /'

  # email addresses
  echo "${text}" | grep -Eo '\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}\b' | sed 's/^/EMAIL: /'
} | awk '!seen[$0]++' \
  |
  # take uniq without sorting
  fzf --multi --prompt "Select item: " \
  | cut -d' ' -f2- | tr -d '\n' | pbcopy
