Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- set -u
- server_started=false
- cleanup() {
- local exit_status=$?
- trap - EXIT INT TERM HUP
- if [[ "$server_started" == true ]]; then
- if ! codex remote-control stop; then
- printf 'cdx: failed to stop the Codex remote-control server\n' >&2
- if ((exit_status == 0)); then
- exit_status=1
- fi
- fi
- fi
- exit "$exit_status"
- }
- trap cleanup EXIT
- trap 'exit 130' INT
- trap 'exit 143' TERM
- trap 'exit 129' HUP
- if ! start_output="$(codex remote-control start --json)"; then
- if [[ -n "$start_output" ]]; then
- printf '%s\n' "$start_output" >&2
- fi
- printf 'cdx: failed to start the Codex remote-control server\n' >&2
- exit 1
- fi
- server_started=true
- if [[ "$start_output" != *'"status":"connected"'* ||
- "$start_output" != *'"timedOut":false'* ]]; then
- printf 'cdx: remote-control server did not report a ready connection\n' >&2
- exit 1
- fi
- printf 'Codex remote control is ready.\n'
- codex --remote unix:// "$@"
Advertisement
Add Comment
Please, Sign In to add comment