From e31124335f1e4623074b2cac870b3f1f3405e205 Mon Sep 17 00:00:00 2001 From: Vladimir Iakovlev Date: Wed, 16 Aug 2017 11:26:43 +0200 Subject: [PATCH] #658: Ensure that history isn't empty in autoconfiguration --- thefuck/not_configured.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/thefuck/not_configured.py b/thefuck/not_configured.py index 8ff5fe268..cbd6f6a63 100644 --- a/thefuck/not_configured.py +++ b/thefuck/not_configured.py @@ -40,6 +40,15 @@ def _record_first_run(): json.dump(info, tracker) +def _get_previous_command(): + history = shell.get_history() + + if history: + return history[-1] + else: + return None + + def _is_second_run(): """Returns `True` when we know that `fuck` called second time.""" tracker_path = _get_not_configured_usage_tracker_path() @@ -56,7 +65,7 @@ def _is_second_run(): if not (isinstance(info, dict) and info.get('pid') == current_pid): return False - return (shell.get_history()[-1] == 'fuck' or + return (_get_previous_command() == 'fuck' or time.time() - info.get('time', 0) < const.CONFIGURATION_TIMEOUT)