#!/bin/sh -e
#
# reposize - curl github repo size

if [ "$#" -eq 0 ]; then
  printf '%s\n' "Usage: ${0##*/} <user/repo>" >&2
  exit 1
fi

url=$(echo "$1" \
  | perl -pe 's#(?:https?://github.com/)([\w\d.-]+\/[\w\d.-]+).*#\1#g' \
  | perl -pe 's#git\@github.com:([\w\d.-]+\/[\w\d.-]+)\.git#\1#g')

if [ -n "${url}" ]; then
  printf '%s' "https://github.com/${url} => "
  curl -s "https://api.github.com/repos/${url}" \
    | jq '.size' \
    | numfmt --to=iec --from-unit=1024
fi
