#!/usr/bin/env bash
#
# cloc-git - temporarily clone a repository and run cloc on it
#
# ---
# https://overflow.adminforge.de/questions/29012789/placeholder#29012789

case "$1" in
  http* | git@*) url="$1" ;;
  github.com/*) url="https://$1" ;;
  *) url="https://github.com/$1" ;;
esac

# tmp="/tmp/temp-linecount-repo"
tmp="${TMPDIR:-/tmp}/temp-linecount-repo"

git clone --depth 1 "${url}" "${tmp}" \
  && printf "('%s' will be deleted automatically.)\n\n\n" "${tmp}" \
  && printf "('temp-linecount-repo' will be deleted automatically)\n\n\n" \
  && cloc "${tmp}" \
  && rm -rf "${tmp}"
