srigi

cdx · Codex TUI server

Jul 16th, 2026 (edited)
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.99 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. set -u
  4.  
  5. server_started=false
  6.  
  7. cleanup() {
  8.   local exit_status=$?
  9.  
  10.   trap - EXIT INT TERM HUP
  11.  
  12.   if [[ "$server_started" == true ]]; then
  13.     if ! codex remote-control stop; then
  14.       printf 'cdx: failed to stop the Codex remote-control server\n' >&2
  15.       if ((exit_status == 0)); then
  16.         exit_status=1
  17.       fi
  18.     fi
  19.   fi
  20.  
  21.   exit "$exit_status"
  22. }
  23.  
  24. trap cleanup EXIT
  25. trap 'exit 130' INT
  26. trap 'exit 143' TERM
  27. trap 'exit 129' HUP
  28.  
  29. if ! start_output="$(codex remote-control start --json)"; then
  30.   if [[ -n "$start_output" ]]; then
  31.     printf '%s\n' "$start_output" >&2
  32.   fi
  33.   printf 'cdx: failed to start the Codex remote-control server\n' >&2
  34.   exit 1
  35. fi
  36.  
  37. server_started=true
  38.  
  39. if [[ "$start_output" != *'"status":"connected"'* ||
  40.       "$start_output" != *'"timedOut":false'* ]]; then
  41.   printf 'cdx: remote-control server did not report a ready connection\n' >&2
  42.   exit 1
  43. fi
  44.  
  45. printf 'Codex remote control is ready.\n'
  46. codex --remote unix:// "$@"
Advertisement
Add Comment
Please, Sign In to add comment