#!/usr/bin/env bash
# hermes-display-env N [command...]
# Without a command: print the display's environment contract (KEY=VALUE lines).
# With a command:     run it with that environment, e.g.
#   hermes-display-env 11 hermes computer-use doctor
#   hermes-display-env 11 cua-driver call get_desktop_state '{}'
set -euo pipefail
N="${1:?usage: hermes-display-env N [command...]}"; shift
ENVF="/run/hermes-display/$N/env"
[[ -r "$ENVF" ]] || { echo "display :$N is not running ($ENVF missing)" >&2; exit 1; }
if [[ $# -eq 0 ]]; then grep -v '^#' "$ENVF"; exit 0; fi
set -a; . "$ENVF"; set +a
exec "$@"
