diff --git a/thefuck/custom_fuckups.py b/thefuck/custom_fuckups.py index a416f647..46258c93 100644 --- a/thefuck/custom_fuckups.py +++ b/thefuck/custom_fuckups.py @@ -12,11 +12,7 @@ # rule is in rules/myfuckups.py -# TODO default fuckups (could replace some existing rules with these, mostly typo rules), share fuckups -# TODO add command that calls add_fuckup() - something like -$ fuck --ifuckedup # not sure how to do this with all these aliases... -# TODO add suggestion to add a fuckup when 'no fucks given' -# TODO add command that calls remove_fuckup() - something like -$ fuck --remove 'cd..' # same problem as add_fuckup - +# TODO default fuckups (could replace some existing rules with these, mostly typo rules) in ~/.thefuck/my_fuckups def get_fuckups(): # returns a dictionary of your fuckups from ~/.thefuck/my_fuckups @@ -41,6 +37,9 @@ def get_fuckups(): # returns a dictionary of your fuckups from ~/.thefuck/my_fuc return fuckups def add_fuckup(fucked, fixed) + + print 'Adding fucked: ' + fucked + ' as fixed: ' + fixed + FILENAME = '~/.thefuck/my_fuckups' FILE = open(FILENAME, 'w') @@ -53,6 +52,8 @@ def add_fuckup(fucked, fixed) def remove_fuckup(fuckup) + print 'Removing fucked: ' + fucked + ' as fixed: ' + fixed + FILENAME = '~/.thefuck/my_fuckups' FILE = open(FILENAME, 'r') diff --git a/thefuck/main.py b/thefuck/main.py index 434d7ebd..f8128ddf 100644 --- a/thefuck/main.py +++ b/thefuck/main.py @@ -8,6 +8,8 @@ from psutil import Process, TimeoutExpired import colorama import six from . import logs, conf, types, shells +import getopt +import custom_fuckups def setup_user_dir(): @@ -66,9 +68,32 @@ def wait_output(settings, popen): proc.kill() return False +def check_args(settings, args, cmd): + """Looks for command line arguments '--ifuckedup=' and '--remove='. + --remove requires relevent fuckup. + --ifuckedup requires relevent fix. + """ + + options, leftovers = getopt.getopt(args, '', ['ifuckedup=', 'remove=']) + + for opt, val in options: + try: + if opt == '--ifuckedup': + custom_fuckups.add_fuckup(cmd, val) + return True + elif opt == '--remove': + custom_fuckups.remove_fuckup(val) + return True + else + return False + except Exception as err: + logs.failed(err, settings) + return False + def get_command(settings, args): """Creates command from `args` and executes it.""" + if six.PY2: script = ' '.join(arg.decode('utf-8') for arg in args[1:]) else: @@ -128,8 +153,11 @@ def main(): colorama.init() user_dir = setup_user_dir() settings = conf.get_settings(user_dir) - command = get_command(settings, sys.argv) + + if check_args(settings, sys.argv[1:], command): + return + if command: rules = get_rules(user_dir, settings) matched_rule = get_matched_rule(command, rules, settings)