mirror of
https://github.com/nvbn/thefuck.git
synced 2025-03-13 22:28:33 +00:00
--ifuckedup and --remove commands for custum fuckups
This commit is contained in:
parent
db3b5f5e5f
commit
a0118fad4e
@ -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')
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user