Last active
August 29, 2015 14:21
-
-
Save fzerorubigd/3edf97198ab8b9797cd9 to your computer and use it in GitHub Desktop.
~/.thefuck/rules/gbvendor.py
This file contains hidden or 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
# a simple rule for thefuck (https://github.com/nvbn/thefuck) to handle the gb vendor in one fucking step :) | |
import re | |
def match(command, settings): | |
m = re.search(r'cannot find package "([^"]*)"', command.stdout) | |
return ('gb' in command.script | |
and m) | |
# I use submodule, but changing this to gb vendor is not hard at all :) | |
def get_new_command(command, settings): | |
m = re.search(r'cannot find package "([^"]*)"', command.stdout) | |
src = m.group(1).split('/', 3) | |
target = '' | |
git = '' | |
if src[0]=='github.com' or src[0]=='bitbucket.org': | |
target = src[0]+'/'+src[1]+'/'+src[2] | |
git = 'https://' + target+'.git' | |
elif src[0]=='golang.org' and src[1]=='x': | |
target = src[0]+'/'+src[1]+'/'+src[2] | |
git = 'https://go.googlesource.com/' +src[2] | |
elif src[0]=='gopkg.in': | |
if len(src)==2: | |
target=src[0]+'/'+src[1] | |
git= 'https://'+target | |
elif len(src)==3: | |
target=src[0]+'/'+src[1]+'/'+src[2] | |
git= 'https://'+target | |
else: | |
return 'echo "Sorry, but i cannot handle it"' | |
return 'git submodule add ' + git + ' vendor/src/' + target | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment