diff options
author | nfnty <git@nfnty.se> | 2017-01-26 21:52:40 +0100 |
---|---|---|
committer | nfnty <git@nfnty.se> | 2017-01-26 21:52:40 +0100 |
commit | 0f657d5940f38bc4f50350c16ca8d2ef01100775 (patch) | |
tree | b8e0333635b6f1e8f22750152f3af065ad7369cb | |
parent | f1c99cb6d6cc7b8f8eff4e9e6c799468c07d2f33 (diff) | |
download | ranger-0f657d5940f38bc4f50350c16ca8d2ef01100775.tar.gz |
gui.widgets.console: Only read history file if it exists
Fixes #781
-rw-r--r-- | ranger/gui/widgets/console.py | 20 |
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: |