From 0f657d5940f38bc4f50350c16ca8d2ef01100775 Mon Sep 17 00:00:00 2001 From: nfnty Date: Thu, 26 Jan 2017 21:52:40 +0100 Subject: gui.widgets.console: Only read history file if it exists Fixes #781 --- ranger/gui/widgets/console.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/ranger/gui/widgets/console.py b/ranger/gui/widgets/console.py index a2e058ad..6a7332c2 100644 --- a/ranger/gui/widgets/console.py +++ b/ranger/gui/widgets/console.py @@ -6,6 +6,7 @@ from __future__ import (absolute_import, division, print_function) import curses +import os import re from collections import deque @@ -40,14 +41,15 @@ class Console(Widget): # pylint: disable=too-many-instance-attributes,too-many- # load history from files if not ranger.args.clean: self.historypath = self.fm.confpath('history') - try: - fobj = open(self.historypath, 'r') - except OSError as ex: - self.fm.notify('Unable to read history file', bad=True, exception=ex) - else: - for line in fobj: - self.history.add(line[:-1]) - fobj.close() + if os.path.exists(self.historypath): + try: + fobj = open(self.historypath, 'r') + except OSError as ex: + self.fm.notify('Failed to read history file', bad=True, exception=ex) + else: + for line in fobj: + self.history.add(line[:-1]) + fobj.close() self.history_backup = History(self.history) # NOTE: the console is considered in the "question mode" when the @@ -71,7 +73,7 @@ class Console(Widget): # pylint: disable=too-many-instance-attributes,too-many- try: fobj = open(self.historypath, 'w') except OSError as ex: - self.fm.notify('Unable to write history file', bad=True, exception=ex) + self.fm.notify('Failed to write history file', bad=True, exception=ex) else: for entry in self.history_backup: try: -- cgit 1.4.1-2-gfad0