github.com/ddev/ddev@v1.23.2-0.20240519125000-d824ffe36ff3/pkg/ddevapp/global_dotddev_assets/commands/host/launch (about)

     1  #!/bin/bash
     2  
     3  ## #ddev-generated: If you want to edit and own this file, remove this line.
     4  ## Description: Launch a browser with the current site
     5  ## Usage: launch [path] [-m|--mailpit]
     6  ## Example: "ddev launch" or "ddev launch /admin/reports/status/php" or "ddev launch phpinfo.php" or "ddev launch https://your.ddev.site" or "ddev launch :3000", for Mailpit "ddev launch -m"
     7  ## Flags: [{"Name":"mailpit","Shorthand":"m","Usage":"ddev launch -m launches the mailpit UI"}]
     8  
     9  if [ "${DDEV_PROJECT_STATUS}" != "running" ] && [ -z "$no_recursion" ]; then
    10    echo "Project ${DDEV_PROJECT} is not running, starting it"
    11    ddev start
    12    start_exit_code=$?
    13    if [ $start_exit_code -ne 0 ]; then
    14      exit $start_exit_code
    15    fi
    16    # run this script again, as the environment is updated after "ddev start"
    17    no_recursion=true ddev "$(basename "$0")" "$@"
    18    exit $?
    19  fi
    20  FULLURL=${DDEV_PRIMARY_URL}
    21  HTTPS=""
    22  if [ ${DDEV_PRIMARY_URL%://*} = "https" ]; then HTTPS=true; fi
    23  
    24  while :; do
    25       case ${1:-} in
    26           -p|--phpmyadmin)
    27              echo "phpMyAdmin is no longer built into DDEV, please 'ddev get ddev/ddev-phpmyadmin' and use 'ddev phpmyadmin' to launch phpMyAdmin" && exit 2
    28              ;;
    29           -m|--mailpit|--mailhog)
    30              if [[ ! -z "${GITPOD_INSTANCE_ID}" ]] || [[ "${CODESPACES}" == "true" ]]; then
    31                  FULLURL="${FULLURL/-${DDEV_HOST_WEBSERVER_PORT}/-${DDEV_HOST_MAILPIT_PORT}}"
    32              else
    33                  if [ "${HTTPS}" = "" ]; then
    34                      FULLURL="${FULLURL%:[0-9]*}:${DDEV_MAILPIT_PORT}"
    35                  else
    36                      FULLURL="${FULLURL%:[0-9]*}:${DDEV_MAILPIT_HTTPS_PORT}"
    37                  fi
    38              fi
    39               ;;
    40  
    41           --)              # End of all options.
    42               shift
    43               break
    44               ;;
    45           -?*)
    46               printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2
    47               ;;
    48           *)               # Default case: No more options, so break out of the loop.
    49               break
    50       esac
    51  
    52       shift
    53   done
    54  
    55  if [ -n "${1:-}" ]; then
    56    if [[ $1 =~ ^https?:// ]]; then
    57      # full url
    58      FULLURL="${1}"
    59    elif [[ $1 =~ ^: ]]; then
    60      # specific port
    61      FULLURL="${FULLURL%:[0-9]*}${1}"
    62      # check if the port is running on https or http
    63      port=$(docker run -i --rm ddev/ddev-utilities sh -c "echo '${1}' | grep -o ':[0-9]\+' | awk -F':' '{print \$2}'" 2>/dev/null)
    64      if [[ "${port}" != "" ]] && ddev describe -j | docker run -i --rm ddev/ddev-utilities sh -c "jq -r '.raw' | grep -w ${port} | grep -q https" 2>/dev/null; then
    65        FULLURL="${FULLURL/http:/https:}"
    66      elif [[ "${port}" != "" ]] && ddev describe -j | docker run -i --rm ddev/ddev-utilities sh -c "jq -r '.raw' | grep -w ${port} | grep -q http" 2>/dev/null; then
    67        FULLURL="${FULLURL/https:/http:}"
    68      fi
    69    else
    70      # relative path
    71      FULLURL="${FULLURL%/}/${1#/}"
    72    fi
    73  fi
    74  
    75  if [[ "${FULLURL}" =~ ^http:// ]]; then
    76    echo "HTTP may redirect to HTTPS in your browser"
    77    echo "See https://ddev.readthedocs.io/en/stable/users/usage/commands/#launch"
    78  fi
    79  
    80  if [ ! -z ${DDEV_DEBUG:-} ]; then
    81      printf "FULLURL $FULLURL\n" && exit 0
    82  fi
    83  
    84  case $OSTYPE in
    85    linux-gnu)
    86      if [[ ! -z "${GITPOD_INSTANCE_ID}" ]]; then
    87          gp preview ${FULLURL}
    88      else
    89          xdg-open ${FULLURL}
    90      fi
    91      ;;
    92    "darwin"*)
    93      open ${FULLURL}
    94      ;;
    95    "win*"* | "msys"*)
    96      start ${FULLURL}
    97      ;;
    98  esac