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.
 
 
 
 

41 rivejä
973 B

  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. rrepo="${proto}://${git_dir}"
  11. # strip user@, :NNN, and .git from input uri's
  12. repo="${destination}/"$(echo "${git_dir}" |
  13. sed -e 's/\.git$//g' |
  14. sed -e 's|.*\@||g' |
  15. sed -e 's|\:[[:digit:]]\{1,\}\/|/|g' |
  16. tr -d '~')
  17. if [ ! -d "${repo}" ]; then
  18. git ls-remote "${rrepo}" > /dev/null 2>&1
  19. if [ $? = 0 ]; then
  20. mkdir -p "${repo}"
  21. echo "git clone ${rrepo} ${repo}"
  22. git clone "${rrepo}" "${repo}"
  23. else
  24. echo "${rrepo} doesn't look to be a git repository"
  25. fi
  26. fi
  27. [ -d "${repo}" ] && cd "${repo}"
  28. }
  29. gh()
  30. {
  31. maybe_git_repo "https://github.com/${1}"
  32. }
  33. bb()
  34. {
  35. maybe_git_repo "https://bitbucket.org/${1}"
  36. }