Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

49 linhas
1.3 KiB

  1. # git/.profile.d/20-functions-git.sh
  2. maybe_git_repo()
  3. {
  4. # assume https if input doesn't contain a protocol
  5. proto=https
  6. destination=${HOME}/src
  7. echo "${1}" | grep '://' > /dev/null 2>&1
  8. [ $? = 0 ] && proto=$(echo "${1}" | sed -e 's|[:]\/\/.*||g')
  9. git_dir=$(echo "${1}" | sed -e 's|.*[:]\/\/||g')
  10. # strip user@, :NNN, and .git from input uri's
  11. repo="${destination}/"$(echo "${git_dir}" |
  12. sed -e 's/\.git$//g' |
  13. sed -e 's|.*\@||g' |
  14. sed -e 's|\:[[:digit:]]\{1,\}\/|/|g' |
  15. tr -d '~')
  16. if [ ! -d "${repo}" ]; then
  17. mkdir -p "${repo}"
  18. echo "git clone ${proto}://${git_dir} ${repo}"
  19. git clone "${proto}://${git_dir}" "${repo}"
  20. ${cmd}
  21. if [ $? != 0 ]; then
  22. # Try removing up to git_dir at worst empty directories.
  23. # Cheap trick, but oldies are goodies.
  24. (
  25. repo_dir="${repo}"
  26. until [ "${repo_dir}" = "${destination}" ]; do
  27. cd "${repo_dir}" > /dev/null 2>&1
  28. rmdir "${repo_dir}" > /dev/null 2>&1
  29. repo_dir=$(echo "${repo_dir}" | sed -e 's/\/[^\/]*$//g')
  30. done
  31. )
  32. echo "git clone of ${proto}://${repo} failed"
  33. fi
  34. fi
  35. [ -d "${repo}" ] && cd "${repo}"
  36. }
  37. gh()
  38. {
  39. maybe_git_repo "https://github.com/${1}"
  40. }
  41. bb()
  42. {
  43. maybe_git_repo "https://bitbucket.org/${1}"
  44. }