Last active
May 27, 2016 17:02
-
-
Save pandada8/4cb63439c3ea295b841dd84fd6bce149 to your computer and use it in GitHub Desktop.
git clone helper
This file contains hidden or 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
#!/bin/env python | |
import os | |
import sys | |
from urllib.parse import urlsplit | |
import subprocess | |
os.chdir(os.path.expanduser("~/repo/")) | |
def clone(url, folder): | |
os.makedirs(folder, exist_ok=True) | |
if os.listdir(folder): | |
print("{} is not empty, not clone.".format(folder)) | |
return | |
subprocess.run(["git", "clone", url, folder]) | |
print("new project cloned at", "~/repo/{}".format(folder)) | |
for i in sys.argv[1:]: | |
print("deal with {}".format(i)) | |
if i.startswith("http"): | |
# is a url and try to clone | |
folder = urlsplit(i).path[1:].rstrip(".git") | |
clone(i, folder) | |
elif i.startswith("git@"): | |
# a ssh protocol | |
folder = i.split(":")[-1].rstrip(".git") | |
clone(i, folder) | |
else: | |
clone("https://github.com/{}.git".format(i), i) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment