From b5dc7aab6d6f8bb0a98089687a40f2477db94e4b Mon Sep 17 00:00:00 2001 From: nvbn Date: Fri, 29 Jan 2016 12:30:31 +0300 Subject: [PATCH] #441: Remove all logic from shells methods wrappers --- thefuck/shells/__init__.py | 10 +++------- thefuck/shells/generic.py | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/thefuck/shells/__init__.py b/thefuck/shells/__init__.py index 870c1ea6..a194f038 100644 --- a/thefuck/shells/__init__.py +++ b/thefuck/shells/__init__.py @@ -43,10 +43,7 @@ def app_alias(alias): def put_to_history(command): - try: - return _get_shell().put_to_history(command) - except IOError: - logs.exception("Can't update history", sys.exc_info()) + return _get_shell().put_to_history(command) def and_(*commands): @@ -54,7 +51,7 @@ def and_(*commands): def get_aliases(): - return list(_get_shell().get_aliases().keys()) + return _get_shell().get_aliases() def split_command(command): @@ -65,9 +62,8 @@ def quote(s): return _get_shell().quote(s) -@memoize def get_history(): - return list(_get_shell().get_history()) + return _get_shell().get_history() def how_to_configure(): diff --git a/thefuck/shells/generic.py b/thefuck/shells/generic.py index 896792cf..248aab45 100644 --- a/thefuck/shells/generic.py +++ b/thefuck/shells/generic.py @@ -2,7 +2,11 @@ import io import os import shlex import six +import sys + +from ..utils import memoize from ..conf import settings +from .. import logs class Generic(object): @@ -35,7 +39,13 @@ class Generic(object): def _get_history_line(self, command_script): return '' - def put_to_history(self, command_script): + def put_to_history(self, command): + try: + return self._put_to_history(command) + except IOError: + logs.exception("Can't update history", sys.exc_info()) + + def _put_to_history(self, command_script): """Puts command script to shell history.""" history_file_name = self._get_history_file_name() if os.path.isfile(history_file_name): @@ -46,7 +56,11 @@ class Generic(object): else: history.write(entry) + @memoize def get_history(self): + return list(self._get_history_lines()) + + def _get_history_lines(self): """Returns list of history entries.""" history_file_name = self._get_history_file_name() if os.path.isfile(history_file_name):