summaryrefslogtreecommitdiff
path: root/alot
diff options
context:
space:
mode:
authorLucas Hoffmann <l-m-h@web.de>2016-07-15 13:04:03 +0200
committerLucas Hoffmann <l-m-h@web.de>2016-12-14 08:46:01 +0100
commit466559bd6db90d98e65da327ed3e0ab78f0c858d (patch)
treea9f5d9cab1508b6cfd3af7ba3003c648a2d5fe29 /alot
parent4b926b31f8d2d2b58dc1332442a14822d6518106 (diff)
Add history_size option
The option allows to limit the size of recent command line entries that are store on disk.
Diffstat (limited to 'alot')
-rw-r--r--alot/defaults/alot.rc.spec6
-rw-r--r--alot/ui.py27
2 files changed, 28 insertions, 5 deletions
diff --git a/alot/defaults/alot.rc.spec b/alot/defaults/alot.rc.spec
index 0bc4f9d9..d99a96e8 100644
--- a/alot/defaults/alot.rc.spec
+++ b/alot/defaults/alot.rc.spec
@@ -239,6 +239,12 @@ msg_summary_hides_threadwide_tags = boolean(default=True)
# first in the account block is used.
reply_account_header_priority = force_list(default=list(From,To,Cc,Envelope-To,X-Envelope-To,Delivered-To))
+# The number of command line history entries to save
+#
+# .. note:: You can set this to -1 to save *all* entries to disk but the
+# history file might get *very* long.
+history_size = integer(default=50)
+
# Key bindings
[bindings]
__many__ = string(default=None)
diff --git a/alot/ui.py b/alot/ui.py
index 84871c18..e44da4ed 100644
--- a/alot/ui.py
+++ b/alot/ui.py
@@ -79,7 +79,8 @@ class UI(object):
self._cache = os.path.join(
os.environ.get('XDG_CACHE_HOME', os.path.expanduser('~/.cache')),
'alot', 'commandhistory')
- self.commandprompthistory = self._load_history_from_file( self._cache)
+ self.commandprompthistory = self._load_history_from_file(
+ self._cache, size=settings.get('history_size'))
# set up main loop
self.mainloop = urwid.MainLoop(self.root_widget,
@@ -675,33 +676,49 @@ class UI(object):
def cleanup(self):
"""Do the final clean up before shutting down."""
- self._save_history_to_file(self.commandprompthistory, self._cache)
+ self._save_history_to_file(self.commandprompthistory, self._cache,
+ size=settings.get('history_size'))
@staticmethod
- def _load_history_from_file(path):
+ def _load_history_from_file(path, size=-1):
"""Load a history list from a file and split it into lines.
:param path: the path to the file that should be loaded
:type path: str
+ :param size: the number of lines to load (0 means no lines, < 0 means
+ all lines)
+ :type size: int
:returns: a list of history items (the lines of the file)
:rtype: list(str)
"""
+ if size == 0:
+ return []
if os.path.exists(path):
- return [line.rstrip('\n') for line in open(path).readlines()]
+ lines = [line.rstrip('\n') for line in open(path).readlines()]
+ if size > 0:
+ lines = lines[-size:]
+ return lines
@staticmethod
- def _save_history_to_file(history, path):
+ def _save_history_to_file(history, path, size=-1):
"""Save a history list to a file for later loading (possibly in another
session).
:param history: the history list to save
:type history: list(str)
:param path: the path to the file where to save the history
+ :param size: the number of lines to save (0 means no lines, < 0 means
+ all lines)
+ :type size: int
:type path: str
:returns: None
"""
+ if size == 0:
+ return
+ if size > 0:
+ history = history[-size:]
directory = os.path.dirname(path)
if not os.path.exists(directory):
os.makedirs(directory)