1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-03-13 22:28:33 +00:00

started learning abilities

This commit is contained in:
Jared Henry Oviatt 2015-05-06 18:05:43 -07:00
parent fc3fcf028a
commit db3b5f5e5f
2 changed files with 90 additions and 0 deletions

75
thefuck/custom_fuckups.py Normal file
View File

@ -0,0 +1,75 @@
# handle reading and writing local list of fuckups
# fuckups are stored in ~/.thefuck/my_fuckups
# file format:
# fucked up command
# fixed command
# fucked up command
# fixed command
# ...
# 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
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)
FILENAME = '~/.thefuck/my_fuckups'
FILE = open(FILENAME, 'w')
FILE.write(fucked + '\n')
FILE.write(fixed + '\n')
FILE.close()
return
def remove_fuckup(fuckup)
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

View File

@ -0,0 +1,15 @@
import 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