github.com/replit/upm@v0.0.0-20240423230255-9ce4fc3ea24c/scripts/browse-godoc.bash (about)

     1  #!/usr/bin/env bash
     2  
     3  set -e
     4  set -o pipefail
     5  
     6  info() {
     7      # Since this script is run in the background from the Makefile,
     8      # this apparently messes up the shell's ability to move the cursor
     9      # back to the leftmost column when a newline is printed. The
    10      # problem is fixed if we manually print a carriage return after
    11      # the message.
    12      echo "$@"$'\r' >&2
    13  }
    14  
    15  # Each loop iteration sleeps for 100ms, so this means an overall
    16  # timeout of 5s.
    17  for i in $(seq 50); do
    18      if curl -s localhost:6060 >/dev/null; then
    19          # Give some extra time for godoc to complete the initial scan.
    20          sleep 0.2
    21          url="http://localhost:6060/pkg/github.com/replit/upm/?m=all"
    22          if command -v xdg-open &>/dev/null; then
    23              info "godoc started; opening $url with xdg-open(1)"
    24              xdg-open "$url"
    25          elif command -v open &>/dev/null; then
    26              info "godoc started; opening $url with open(1)"
    27              open "$url"
    28          else
    29              info "please install either open(1) or xdg-open(1)"
    30              exit 1
    31          fi
    32          exit 1
    33      fi
    34      sleep 0.1
    35  done
    36  
    37  info "godoc failed to start listening on port 6060"
    38  exit 1