executable_git_directories_to_domain.sh 860 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env bash
  2. git_https_repository_to_domain_name()
  3. {
  4. echo "$(git -C "$(dirname "$1")" remote -v)" \
  5. | grep origin \
  6. | head -n 1 \
  7. | grep -oP 'https://(.*)/' \
  8. | sed 's@https://@@; s@/.*@@'
  9. }
  10. git_ssh_repository_to_domain_name()
  11. {
  12. echo "$(git -C "$(dirname "$1")" remote -v)" \
  13. | grep origin \
  14. | head -n 1 \
  15. | grep -oP 'git@(.*):' \
  16. | sed 's/git@//; s/://'
  17. }
  18. for dir in */.git
  19. do
  20. domain="$(git_https_repository_to_domain_name "$dir")"
  21. if [[ $domain != "" ]]
  22. then
  23. echo mkdir -p "$domain"
  24. echo sudo mv "$(dirname "$dir")" "$domain"
  25. fi
  26. done
  27. for dir in */.git
  28. do
  29. domain="$(git_ssh_repository_to_domain_name "$dir")"
  30. if [[ $domain != "" ]]
  31. then
  32. echo mkdir -p "$domain"
  33. echo sudo mv "$(dirname "$dir")" "$domain"
  34. fi
  35. done