Last active
August 29, 2015 14:05
-
-
Save homburg/4d03c97136d01ab76e44 to your computer and use it in GitHub Desktop.
git clone to home dir + repo path
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
#!/usr/bin/env python | |
import os, sys, errno | |
if len(sys.argv) <= 1: | |
os.execlp("git", "git") | |
repo = str(sys.argv[-1]) | |
if repo.endswith(".git"): | |
repo = repo[:-4] | |
if "/" not in repo: | |
os.execlp("git", "git") | |
if repo.count(":") == 1: | |
if "@" in repo: | |
repo_parts = repo[repo.find("@")+1:].replace(":", "/").split("/") | |
else: | |
repo_parts = repo.replace(":", "/").split("/") | |
repo = "git@" + repo | |
elif repo.count("/") == 1: | |
# Something from github | |
repo_parts = ["github.com"] + repo.split("/") | |
repo = "[email protected]:%s.git" % repo | |
else: | |
# http repo? | |
print("TODO...") | |
exit(1) | |
target_dir = os.path.join(os.getenv("HOME"), "src", *repo_parts) | |
try: | |
os.makedirs(target_dir) | |
except OSError as exc: | |
if exc.errno == errno.EEXIST and os.path.isdir(target_dir): | |
pass | |
else: | |
raise | |
os.execlp("git", "git", "clone", repo, target_dir) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment