diff --git a/thefuck/conf.py b/thefuck/conf.py index e107329a..aa5f0bec 100644 --- a/thefuck/conf.py +++ b/thefuck/conf.py @@ -34,6 +34,8 @@ DEFAULT_SETTINGS = {'rules': DEFAULT_RULES, 'priority': {}, 'env': {'LC_ALL': 'C', 'LANG': 'C', 'GIT_TRACE': '1'}} +DEFAULT_FUCKUPS = {'cd..':'cd ..'} + ENV_TO_ATTR = {'THEFUCK_RULES': 'rules', 'THEFUCK_EXCLUDE_RULES': 'exclude_rules', 'THEFUCK_WAIT_COMMAND': 'wait_command', @@ -138,3 +140,13 @@ def initialize_settings_file(user_dir): settings_file.write(SETTINGS_HEADER) for setting in DEFAULT_SETTINGS.items(): settings_file.write(u'# {} = {}\n'.format(*setting)) + + +def initialize_fuckups_file(user_dir): + fuckups_path = user_dir.joinpath('.my_fuckups') + if not fuckups_path.is_file(): + with fuckups_path.open(mode='w') as fuckups_file: + for key, fix in DEFAULT_FUCKUPS.iteritems(): + fuckups_file.write(key + '\n') + fuckups_file.write(fix + '\n') + return diff --git a/thefuck/custom_fuckups.py b/thefuck/custom_fuckups.py new file mode 100644 index 00000000..2152ff27 --- /dev/null +++ b/thefuck/custom_fuckups.py @@ -0,0 +1,74 @@ + +# handle reading and writing local list of fuckups + +# fuckups are stored locally in ~/.thefuck/my_fuckups + +# file format: +# fucked up command +# fixed command +# fucked up command +# fixed command +# ... + +# rule is in rules/myfuckups.py + +def get_fuckups(): # returns a dictionary of your fuckups from ~/.thefuck/.my_fuckups + + FILENAME = '~/.thefuck/.my_fuckups' + FILE = open(FILENAME, 'r') + + IS_FUCKUP = True + + fuckups = dict() + + for line in FILE: + if IS_FUCKUP: + key = line + IS_FUCKUP = False + else: + cmd = line + IS_FUCKUP = True + fuckups[key] = cmd + + FILE.close() + + return fuckups + +def add_fuckup(fucked, fixed): + + print ('Adding fucked: ' + fucked + ' as fixed: ' + fixed) + + FILENAME = '~/.thefuck/.my_fuckups' + FILE = open(FILENAME, 'w') + + FILE.write(fucked + '\n') + FILE.write(fixed + '\n') + + FILE.close() + + return + +def remove_fuckup(fuckup): + + print ('Removing fucked: ' + fucked + ' as fixed: ' + fixed) + + FILENAME = '~/.thefuck/.my_fuckups' + FILE = open(FILENAME, 'r') + + fuckup_cmd = '' + + lines = FILE.readlines() + + FILE.close + + FILE = open(FILENAME, 'w') + + for number, line in enumerate(lines): + if line != fuckup and line != fuckup_cmd: + FILE.write(line) + elif line == fuckup: + fuckup_cmd = lines[number + 1] + + FILE.close() + + return diff --git a/thefuck/rules/my_fuckups.py b/thefuck/rules/my_fuckups.py new file mode 100644 index 00000000..e7d5fada --- /dev/null +++ b/thefuck/rules/my_fuckups.py @@ -0,0 +1,15 @@ + +import thefuck.custom_fuckups + +fuckups = custom_fuckups.get_fuckups() + +def match(command, settings): + if command in fuckups: + return True + return False # not found + + +def get_new_command(command, settings): + return fuckups[command] + +# priority = 1000 # Lower first