Skip to content

Instantly share code, notes, and snippets.

Created June 12, 2014 18:58
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save anonymous/760b8939cff0855300b8 to your computer and use it in GitHub Desktop.
#!/bin/python
import sys
import re
import subprocess as sp
if(len(sys.argv) < 2):
sp.call('git clone')
sys.exit()
args = ' '.join(sys.argv[1:])
iterator = iter(sys.argv[1:])
for arg in iterator:
if(re.match('^-', arg)):
if(re.match('^(--(reference|origin|branch|upload-pack|template|config|depth|separate-git-dir)|-[obuc])', arg)):
next(iterator)
else:
if(not re.match('^((ssh|git|http|https)://|git@)', arg)):
args = args.replace(arg, '').strip()
if(re.match('[a-zA-Z0-9]+/[a-zA-Z0-9]+', arg)):
sp.call('git clone %s git@github.com:%s' % (args, arg))
else:
# this seems overly complicated for the output
p = sp.Popen('git config --get user.user', stdout = sp.PIPE)
(user, e) = p.communicate()
if(not len(user)):
print 'Missing user.user in gitconfig'
sys.exit()
else:
sp.call('git clone %s git@github.com:%s/%s' % (args, user.strip('\r\n'), arg))
else:
sp.call('git clone %s' % (args))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment