#N/A Add history rule
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
from difflib import get_close_matches
|
||||
from thefuck.shells import get_history
|
||||
from thefuck.utils import get_closest, memoize
|
||||
from thefuck.rules.no_command import get_all_callables
|
||||
|
||||
|
||||
@memoize
|
||||
def _history_of_exists_without_current(command):
|
||||
callables = get_all_callables()
|
||||
return [line for line in get_history()
|
||||
if line != command.script
|
||||
and line.split(' ')[0] in callables]
|
||||
|
||||
|
||||
def match(command, settings):
|
||||
return len(get_close_matches(command.script,
|
||||
_history_of_exists_without_current(command)))
|
||||
|
||||
|
||||
def get_new_command(command, settings):
|
||||
return get_closest(command.script,
|
||||
_history_of_exists_without_current(command))
|
||||
|
||||
priority = 9999
|
||||
@@ -1,7 +1,7 @@
|
||||
from difflib import get_close_matches
|
||||
import os
|
||||
from pathlib import Path
|
||||
from thefuck.utils import sudo_support
|
||||
from thefuck.utils import sudo_support, memoize
|
||||
from thefuck.shells import thefuck_alias, get_aliases
|
||||
|
||||
|
||||
@@ -12,7 +12,8 @@ def _safe(fn, fallback):
|
||||
return fallback
|
||||
|
||||
|
||||
def _get_all_callables():
|
||||
@memoize
|
||||
def get_all_callables():
|
||||
tf_alias = thefuck_alias()
|
||||
return [exe.name
|
||||
for path in os.environ.get('PATH', '').split(':')
|
||||
@@ -25,14 +26,14 @@ def _get_all_callables():
|
||||
def match(command, settings):
|
||||
return 'not found' in command.stderr and \
|
||||
bool(get_close_matches(command.script.split(' ')[0],
|
||||
_get_all_callables()))
|
||||
get_all_callables()))
|
||||
|
||||
|
||||
@sudo_support
|
||||
def get_new_command(command, settings):
|
||||
old_command = command.script.split(' ')[0]
|
||||
new_command = get_close_matches(old_command,
|
||||
_get_all_callables())[0]
|
||||
get_all_callables())[0]
|
||||
return ' '.join([new_command] + command.script.split(' ')[1:])
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user