#N/A Move get_all_executables (formerly get_all_callables) to utils
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
from difflib import get_close_matches
|
||||
from thefuck.shells import get_history, thefuck_alias
|
||||
from thefuck.utils import get_closest, memoize
|
||||
from thefuck.rules.no_command import get_all_callables
|
||||
from thefuck.utils import get_closest, memoize, get_all_executables
|
||||
|
||||
|
||||
def _not_corrected(history, tf_alias):
|
||||
@@ -19,10 +18,10 @@ def _not_corrected(history, tf_alias):
|
||||
def _history_of_exists_without_current(command):
|
||||
history = get_history()
|
||||
tf_alias = thefuck_alias()
|
||||
callables = get_all_callables()
|
||||
executables = get_all_executables()
|
||||
return [line for line in _not_corrected(history, tf_alias)
|
||||
if not line.startswith(tf_alias) and not line == command.script
|
||||
and line.split(' ')[0] in callables]
|
||||
and line.split(' ')[0] in executables]
|
||||
|
||||
def match(command, settings):
|
||||
return len(get_close_matches(command.script,
|
||||
|
||||
@@ -1,39 +1,19 @@
|
||||
from difflib import get_close_matches
|
||||
import os
|
||||
from pathlib import Path
|
||||
from thefuck.utils import sudo_support, memoize
|
||||
from thefuck.shells import thefuck_alias, get_aliases
|
||||
|
||||
|
||||
def _safe(fn, fallback):
|
||||
try:
|
||||
return fn()
|
||||
except OSError:
|
||||
return fallback
|
||||
|
||||
|
||||
@memoize
|
||||
def get_all_callables():
|
||||
tf_alias = thefuck_alias()
|
||||
return [exe.name
|
||||
for path in os.environ.get('PATH', '').split(':')
|
||||
for exe in _safe(lambda: list(Path(path).iterdir()), [])
|
||||
if not _safe(exe.is_dir, True)] + [
|
||||
alias for alias in get_aliases() if alias != tf_alias]
|
||||
from thefuck.utils import sudo_support, get_all_executables
|
||||
|
||||
|
||||
@sudo_support
|
||||
def match(command, settings):
|
||||
return 'not found' in command.stderr and \
|
||||
bool(get_close_matches(command.script.split(' ')[0],
|
||||
get_all_callables()))
|
||||
get_all_executables()))
|
||||
|
||||
|
||||
@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_executables())[0]
|
||||
return ' '.join([new_command] + command.script.split(' ')[1:])
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user