Created
October 16, 2020 11:13
-
-
Save knownothingsnow/a3e417a02fe9835c464b1f68709ac870 to your computer and use it in GitHub Desktop.
通过 www.gitclone.com 加速 github clone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
,gitclone(){ | |
if [[ "$1" =~ ^git@github.com ]]; then | |
local repo=$(echo $1 | grep -Po '(?<=git@github\.com:)[\w-]+\/[\w-]+') | |
local origin_url=$1 | |
elif [[ $1 =~ ^https://github.com ]]; then | |
local repo=$(echo $1 | grep -Po '(?<=https:\/\/github\.com\/)[\w-]+\/[\w-]+') | |
local origin_url=$1 | |
elif [[ $1 == "gh" ]]; then | |
local repo=${4} | |
local origin_url="git@github.com:$repo.git" | |
else | |
echo "Url isn't vaild." | |
fi | |
local repo_name=$(echo $repo | grep -Po '(?<=\/)[\w-]+') | |
local new_url="https://gitclone.com/github.com/$repo.git" | |
echo "start downloading : ${repo}" && git clone $new_url | |
if [ -d $repo_name ] && [ $? == 0 ]; then | |
cd ./$repo_name && git remote rename origin mirror && git remote add origin $origin_url && cd - | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment