mirror of
https://github.com/nvbn/thefuck.git
synced 2025-01-19 04:21:14 +00:00
#209 add support of aliases to no_command
This commit is contained in:
parent
5319871326
commit
2c3df1ad47
@ -3,7 +3,7 @@ from thefuck.rules.no_command import match, get_new_command
|
||||
|
||||
|
||||
def test_match():
|
||||
with patch('thefuck.rules.no_command._get_all_bins',
|
||||
with patch('thefuck.rules.no_command._get_all_callables',
|
||||
return_value=['vim', 'apt-get']):
|
||||
assert match(Mock(stderr='vom: not found', script='vom file.py'), None)
|
||||
assert not match(Mock(stderr='qweqwe: not found', script='qweqwe'), None)
|
||||
@ -11,7 +11,7 @@ def test_match():
|
||||
|
||||
|
||||
def test_get_new_command():
|
||||
with patch('thefuck.rules.no_command._get_all_bins',
|
||||
with patch('thefuck.rules.no_command._get_all_callables',
|
||||
return_value=['vim', 'apt-get']):
|
||||
assert get_new_command(
|
||||
Mock(stderr='vom: not found',
|
||||
|
@ -2,6 +2,7 @@ from difflib import get_close_matches
|
||||
import os
|
||||
from pathlib import Path
|
||||
from thefuck.utils import sudo_support
|
||||
from thefuck.shells import get_aliases
|
||||
|
||||
|
||||
def _safe(fn, fallback):
|
||||
@ -11,25 +12,25 @@ def _safe(fn, fallback):
|
||||
return fallback
|
||||
|
||||
|
||||
def _get_all_bins():
|
||||
def _get_all_callables():
|
||||
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)]
|
||||
if not _safe(exe.is_dir, True)] + get_aliases()
|
||||
|
||||
|
||||
@sudo_support
|
||||
def match(command, settings):
|
||||
return 'not found' in command.stderr and \
|
||||
bool(get_close_matches(command.script.split(' ')[0],
|
||||
_get_all_bins()))
|
||||
_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_bins())[0]
|
||||
_get_all_callables())[0]
|
||||
return ' '.join([new_command] + command.script.split(' ')[1:])
|
||||
|
||||
|
||||
|
@ -186,4 +186,4 @@ def and_(*commands):
|
||||
|
||||
|
||||
def get_aliases():
|
||||
return _get_shell().get_aliases().keys()
|
||||
return list(_get_shell().get_aliases().keys())
|
||||
|
Loading…
x
Reference in New Issue
Block a user