Last active
August 29, 2015 14:25
-
-
Save jstacoder/269be295dbe0f3e33b2e to your computer and use it in GitHub Desktop.
easily clone github repos
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 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