From a2ec5aa3ff3c58bf982db062b48d9dd2b8738c68 Mon Sep 17 00:00:00 2001 From: nvbn Date: Fri, 29 Jan 2016 12:22:31 +0300 Subject: [PATCH] #441: Move function for getting current alias to `utils` --- tests/rules/test_history.py | 2 +- thefuck/main.py | 4 ++-- thefuck/rules/history.py | 6 +++--- thefuck/rules/switch_lang.py | 5 ++--- thefuck/shells/__init__.py | 4 ---- thefuck/utils.py | 8 ++++++-- 6 files changed, 14 insertions(+), 15 deletions(-) diff --git a/tests/rules/test_history.py b/tests/rules/test_history.py index 6422743b..e50d0afd 100644 --- a/tests/rules/test_history.py +++ b/tests/rules/test_history.py @@ -12,7 +12,7 @@ def history(mocker): @pytest.fixture def alias(mocker): - return mocker.patch('thefuck.rules.history.thefuck_alias', + return mocker.patch('thefuck.rules.history.get_alias', return_value='fuck') diff --git a/thefuck/main.py b/thefuck/main.py index 76468a9b..c4e075bc 100644 --- a/thefuck/main.py +++ b/thefuck/main.py @@ -11,7 +11,7 @@ from . import logs, types, shells from .conf import settings from .corrector import get_corrected_commands from .exceptions import EmptyCommand -from .utils import get_installation_info +from .utils import get_installation_info, get_alias from .ui import select_command @@ -42,7 +42,7 @@ def print_alias(entry_point=True): else: position = 2 - alias = shells.thefuck_alias() + alias = get_alias() if len(sys.argv) > position: alias = sys.argv[position] print(shells.app_alias(alias)) diff --git a/thefuck/rules/history.py b/thefuck/rules/history.py index 0f187d99..31a3d2f0 100644 --- a/thefuck/rules/history.py +++ b/thefuck/rules/history.py @@ -1,6 +1,6 @@ from difflib import get_close_matches -from thefuck.shells import get_history, thefuck_alias -from thefuck.utils import get_closest, memoize, get_all_executables +from thefuck.shells import get_history +from thefuck.utils import get_closest, memoize, get_all_executables, get_alias def _not_corrected(history, tf_alias): @@ -17,7 +17,7 @@ def _not_corrected(history, tf_alias): @memoize def _history_of_exists_without_current(command): history = get_history() - tf_alias = thefuck_alias() + tf_alias = get_alias() 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 diff --git a/thefuck/rules/switch_lang.py b/thefuck/rules/switch_lang.py index 23f1422d..b1abb63d 100644 --- a/thefuck/rules/switch_lang.py +++ b/thefuck/rules/switch_lang.py @@ -1,6 +1,5 @@ # -*- encoding: utf-8 -*- -from thefuck.shells import thefuck_alias -from thefuck.utils import memoize +from thefuck.utils import memoize, get_alias target_layout = '''qwertyuiop[]asdfghjkl;'zxcvbnm,./QWERTYUIOP{}ASDFGHJKL:"ZXCVBNM<>?''' @@ -35,7 +34,7 @@ def match(command): return False matched_layout = _get_matched_layout(command) return matched_layout and \ - _switch_command(command, matched_layout) != thefuck_alias() + _switch_command(command, matched_layout) != get_alias() def get_new_command(command): diff --git a/thefuck/shells/__init__.py b/thefuck/shells/__init__.py index 7cbe5d4b..870c1ea6 100644 --- a/thefuck/shells/__init__.py +++ b/thefuck/shells/__init__.py @@ -42,10 +42,6 @@ def app_alias(alias): return _get_shell().app_alias(alias) -def thefuck_alias(): - return os.environ.get('TF_ALIAS', 'fuck') - - def put_to_history(command): try: return _get_shell().put_to_history(command) diff --git a/thefuck/utils.py b/thefuck/utils.py index 101bcd25..01b75183 100644 --- a/thefuck/utils.py +++ b/thefuck/utils.py @@ -93,7 +93,7 @@ def get_closest(word, possibilities, n=3, cutoff=0.6, fallback_to_first=True): @memoize def get_all_executables(): - from thefuck.shells import thefuck_alias, get_aliases + from thefuck.shells import get_aliases def _safe(fn, fallback): try: @@ -101,7 +101,7 @@ def get_all_executables(): except OSError: return fallback - tf_alias = thefuck_alias() + tf_alias = get_alias() tf_entry_points = get_installation_info().get_entry_map()\ .get('console_scripts', {})\ .keys() @@ -260,3 +260,7 @@ def compatibility_call(fn, *args): def get_installation_info(): return pkg_resources.require('thefuck')[0] + + +def get_alias(): + return os.environ.get('TF_ALIAS', 'fuck')