From 2c3df1ad47f56eea63c931d6df5abb44e5a7b837 Mon Sep 17 00:00:00 2001 From: nvbn Date: Wed, 20 May 2015 16:58:05 +0300 Subject: [PATCH] #209 add support of aliases to `no_command` --- tests/rules/test_no_command.py | 4 ++-- thefuck/rules/no_command.py | 9 +++++---- thefuck/shells.py | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/rules/test_no_command.py b/tests/rules/test_no_command.py index 64a2423a..68ccf3f7 100644 --- a/tests/rules/test_no_command.py +++ b/tests/rules/test_no_command.py @@ -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', diff --git a/thefuck/rules/no_command.py b/thefuck/rules/no_command.py index 1a152c99..3b310495 100644 --- a/thefuck/rules/no_command.py +++ b/thefuck/rules/no_command.py @@ -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:]) diff --git a/thefuck/shells.py b/thefuck/shells.py index ee49ea0d..2749a1c5 100644 --- a/thefuck/shells.py +++ b/thefuck/shells.py @@ -186,4 +186,4 @@ def and_(*commands): def get_aliases(): - return _get_shell().get_aliases().keys() + return list(_get_shell().get_aliases().keys())