You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.0 KiB

  1. #!/bin/sh
  2. NAME="Alejandro Mery"
  3. EMAIL="amery@geeks.cl"
  4. BASE="git@github.com:amery/"
  5. err() {
  6. if [ $# -eq 0 ]; then
  7. cat
  8. else
  9. echo "$*"
  10. fi >&2
  11. }
  12. usage() {
  13. [ $# -eq 0 ] || echo "$*" >&2
  14. err <<-EOT
  15. Usage: $0 <remote> [<dir>]
  16. EOT
  17. exit 1
  18. }
  19. [ $# -eq 1 -o $# -eq 2 ] || usage
  20. if expr "$1" : '.*:' > /dev/null; then
  21. REMOTE="$1"
  22. else
  23. REMOTE="$BASE$1"
  24. fi
  25. DIR="${2:-${REMOTE##*/}}"
  26. if [ ! -d "$DIR/.git" ]; then
  27. mkdir -p "$DIR" && cd "$DIR" && git init || exit $?
  28. else
  29. cd "$DIR" || exit $?
  30. err "WARNING: $PWD already under git control"
  31. fi
  32. for x in \
  33. "user.name:$NAME" \
  34. "user.email:$EMAIL" \
  35. "remote.origin.url:$REMOTE" \
  36. ; do
  37. k="${x%%:*}"
  38. v="${x#*:}"
  39. x="$(git config "$k")"
  40. if [ -z "$v" ]; then
  41. continue
  42. elif [ -z "$x" -a "$k" = "remote.origin.url" ]; then
  43. git remote add origin "$v"
  44. elif [ "$v" != "$x" ]; then
  45. [ -z "$x" ] || err "WARNING:$k: $x -> $v"
  46. git config "$k" "$v"
  47. fi
  48. x=$(git config "$k")
  49. if [ "$v" = "$x" ]; then
  50. echo "$k=$v"
  51. else
  52. err "ERROR:$k: set to '$x' instead of '$v'"
  53. fi
  54. done
  55. echo "Enjoy! \`cd $DIR\`"