git-get 582 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/bin/sh
  2. DOMAIN=github.com
  3. USER=ambrevar
  4. usage () {
  5. cat <<EOF>&2
  6. Usage: ${0##*/} [OPTIONS] REPOS
  7. Clone git repo(s) from $DOMAIN:$USER.
  8. Options:
  9. -d DOMAIN: Set domain.
  10. -u USER: Set repository owner.
  11. EOF
  12. }
  13. while getopts ":d:u:" opt; do
  14. case $opt in
  15. d)
  16. DOMAIN=$OPTARG ;;
  17. u)
  18. USER=$OPTARG ;;
  19. \?)
  20. usage
  21. exit 1 ;;
  22. esac
  23. done
  24. shift $((OPTIND - 1))
  25. if [ $# -eq 0 ]; then
  26. usage
  27. exit 1
  28. fi
  29. if ! command -v git >/dev/null 2>&1; then
  30. echo >&2 "'git' not found"
  31. exit 1
  32. fi
  33. for i; do
  34. git clone "git@$DOMAIN:/$USER/$i" || git clone "https://$DOMAIN/$USER/$i"
  35. done