diff --git a/README.md b/README.md index 199f37b8..9f3b2168 100644 --- a/README.md +++ b/README.md @@ -302,7 +302,8 @@ Or via environment variables: * `THEFUCK_NO_COLORS` – disable colored output, `true/false`; * `THEFUCK_PRIORITY` – priority of the rules, like `no_command=9999:apt_get=100`, rule with lower `priority` will be matched first; -* `THEFUCK_DEBUG` – enables debug output, `true/false`. +* `THEFUCK_DEBUG` – enables debug output, `true/false`; +* `THEFUCK_HISTORY_LIMIT` – how many history commands will be scanned, like `2000`. For example: diff --git a/thefuck/conf.py b/thefuck/conf.py index 3e6e55f5..47eaf34c 100644 --- a/thefuck/conf.py +++ b/thefuck/conf.py @@ -24,7 +24,8 @@ ENV_TO_ATTR = {'THEFUCK_RULES': 'rules', 'THEFUCK_REQUIRE_CONFIRMATION': 'require_confirmation', 'THEFUCK_NO_COLORS': 'no_colors', 'THEFUCK_PRIORITY': 'priority', - 'THEFUCK_DEBUG': 'debug'} + 'THEFUCK_DEBUG': 'debug', + 'THEFUCK_HISTORY_LIMIT': 'history_limit'} SETTINGS_HEADER = u"""# ~/.thefuck/settings.py: The Fuck settings file # @@ -125,3 +126,4 @@ class Settings(dict): settings = Settings(DEFAULT_SETTINGS) +settings.init() diff --git a/thefuck/shells.py b/thefuck/shells.py index 97d51a43..d82a88ba 100644 --- a/thefuck/shells.py +++ b/thefuck/shells.py @@ -10,6 +10,7 @@ from time import time import io import os from .utils import DEVNULL, memoize, cache +from .conf import settings class Generic(object): @@ -59,10 +60,16 @@ class Generic(object): def get_history(self): """Returns list of history entries.""" + tail_num = settings.get("history_limit", None) history_file_name = self._get_history_file_name() if os.path.isfile(history_file_name): - with io.open(history_file_name, 'r', - encoding='utf-8', errors='ignore') as history: + if tail_num is not None: + _, f = os.popen2("tail -n {} {}".format(tail_num, history_file_name)) + _.close() + else: + f = io.open(history_file_name, 'r', + encoding='utf-8', errors='ignore') + with f as history: for line in history: prepared = self._script_from_history(line)\ .strip()