mirror of
https://github.com/nvbn/thefuck.git
synced 2025-03-14 06:38:32 +00:00
Merge f536c0b1ade36d6c158616b6786f214a18600e9b into 191a2e588d0c2969d375a5cf3b35394b49cbf100
This commit is contained in:
commit
307ae08c03
@ -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
|
||||
|
74
thefuck/custom_fuckups.py
Normal file
74
thefuck/custom_fuckups.py
Normal file
@ -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
|
15
thefuck/rules/my_fuckups.py
Normal file
15
thefuck/rules/my_fuckups.py
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user