summary refs log tree commit diff stats
diff options
context:
space:
mode:
authornfnty <git@nfnty.se>2017-01-26 21:52:40 +0100
committernfnty <git@nfnty.se>2017-01-26 21:52:40 +0100
commit0f657d5940f38bc4f50350c16ca8d2ef01100775 (patch)
treeb8e0333635b6f1e8f22750152f3af065ad7369cb
parentf1c99cb6d6cc7b8f8eff4e9e6c799468c07d2f33 (diff)
downloadranger-0f657d5940f38bc4f50350c16ca8d2ef01100775.tar.gz
gui.widgets.console: Only read history file if it exists
Fixes #781
-rw-r--r--ranger/gui/widgets/console.py20
1 files 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: