#!/usr/bin/env bash
set -euo pipefail

[[ "${1:-}" == get ]] || exit 0

host="" protocol=""
while IFS='=' read -r key value; do
  [[ -z "$key" ]] && break
  case "$key" in
    host) host="$value" ;;
    protocol) protocol="$value" ;;
  esac
done

protocol_lc="$(printf '%s' "$protocol" | tr '[:upper:]' '[:lower:]')"
host_lc="$(printf '%s' "${host%%:*}" | tr '[:upper:]' '[:lower:]')"
[[ "$protocol_lc" == https && "$host_lc" == github.com ]] || exit 0

token="$("$HOME/.claude/bot-shims/bot-token")"
echo username=x-access-token
echo "password=$token"
