Skip to content

Instantly share code, notes, and snippets.

@homburg
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save homburg/4d03c97136d01ab76e44 to your computer and use it in GitHub Desktop.
Save homburg/4d03c97136d01ab76e44 to your computer and use it in GitHub Desktop.
git clone to home dir + repo path
#!/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 = "git@github.com:%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