Skip to content

Instantly share code, notes, and snippets.

@jstacoder
Last active August 29, 2015 14:25
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 jstacoder/269be295dbe0f3e33b2e to your computer and use it in GitHub Desktop.
Save jstacoder/269be295dbe0f3e33b2e to your computer and use it in GitHub Desktop.
easily clone github repos
#!/usr/bin/env python
import commands
import sys
from functools import partial
CMD = 'git clone {protocol}{sep1}github.com{sep2}{user}/{repo}.git'
make_cmd = lambda **kwargs: CMD.format(**kwargs)
ssh = partial(make_cmd,protocol='git',sep1='@',sep2=':')
https = partial(make_cmd,protocol='https',sep1='://',sep2='/')
def print_usage():
print '''Usage:
{} --user GITHUB_USER --repo REPO_NAME
will clone REPO_NAME from GITHUB_USER's account
'''.format(__file__)
sys.exit(1)
def run():
('--user' in sys.argv and '--repo' in sys.argv) or print_usage()
return commands.getoutput(
dict(
ssh=ssh,
https=https,
)[all(filter(lambda x: 'https' not in x,sys.argv)) and 'ssh' or 'https'](
user=(sys.argv[sys.argv.index('--user')+1]),
repo=(sys.argv[sys.argv.index('--repo')+1])
)
)
if __name__ == "__main__":
print run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment