mirror of
https://github.com/nvbn/thefuck.git
synced 2025-03-14 06:38:32 +00:00
allow commands to wraps other commands for correction
This commit is contained in:
parent
6975d30818
commit
31fa0bae12
@ -40,6 +40,7 @@ DEFAULT_SETTINGS = {'rules': DEFAULT_RULES,
|
||||
'wait_slow_command': 15,
|
||||
'slow_commands': ['lein', 'react-native', 'gradle',
|
||||
'./gradlew', 'vagrant'],
|
||||
'wraps_commands': {},
|
||||
'repeat': False,
|
||||
'instant_mode': False,
|
||||
'num_close_matches': 3,
|
||||
|
@ -11,5 +11,5 @@ def match(command):
|
||||
|
||||
@git_support
|
||||
def get_new_command(command):
|
||||
formatme = shell.and_('git stash', '{}')
|
||||
formatme = shell.and_('{} stash'.format(command.script_parts[0]), '{}')
|
||||
return formatme.format(command.script)
|
||||
|
@ -11,7 +11,8 @@ def match(command):
|
||||
|
||||
@git_support
|
||||
def get_new_command(command):
|
||||
return shell.and_('git add --update', 'git stash pop', 'git reset .')
|
||||
cmd = command.script_parts[0]
|
||||
return shell.and_('{} add --update'.format(cmd), '{} stash pop'.format(cmd), '{} reset .'.format(cmd))
|
||||
|
||||
|
||||
# make it come before the other applicable rules
|
||||
|
@ -19,7 +19,7 @@ def _get_actual_scm():
|
||||
return scm
|
||||
|
||||
|
||||
@for_app(*wrong_scm_patterns.keys())
|
||||
@for_app(*wrong_scm_patterns.keys(), strict=True)
|
||||
def match(command):
|
||||
scm = command.script_parts[0]
|
||||
pattern = wrong_scm_patterns[scm]
|
||||
|
@ -167,15 +167,23 @@ def replace_command(command, broken, matched):
|
||||
|
||||
|
||||
@memoize
|
||||
def is_app(command, *app_names, **kwargs):
|
||||
"""Returns `True` if command is call to one of passed app names."""
|
||||
def is_app(command, *app_names, strict=False, **kwargs):
|
||||
"""Returns `True` if command is call to one of passed app names. If `strict=True`, skip checking for wrapped commands."""
|
||||
|
||||
at_least = kwargs.pop('at_least', 0)
|
||||
if kwargs:
|
||||
raise TypeError("got an unexpected keyword argument '{}'".format(kwargs.keys()))
|
||||
|
||||
if len(command.script_parts) > at_least:
|
||||
return command.script_parts[0] in app_names
|
||||
cmd = command.script_parts[0]
|
||||
if cmd in app_names:
|
||||
return True
|
||||
if not strict:
|
||||
# allow command to be wrapped as another command
|
||||
wrapped_cmd = [settings['wraps_commands'].get(a, []) for a in app_names]
|
||||
for wrapped in wrapped_cmd:
|
||||
if cmd in wrapped:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user