-
Notifications
You must be signed in to change notification settings - Fork 124
Closed
Description
It would be nice if there was an easy way to add persistent history to cmd2 applications.
We would need to decide if this is done for readline history, cmd2 history command history, or both. Perhaps there would be two separate options for making each of these persistent?
We could probably add an optional argument or two (with default values) to the cmd2.Cmd.init() initializer.
This blog post demonstrates the basics of how to make the readline history persistent:
import os
import atexit
import readline
history_file = os.path.expanduser('~/.mycli_history')
if not os.path.exists(history_file):
with open(history_file, "w") as fobj:
fobj.write("")
readline.read_history_file(history_file)
atexit.register(readline.write_history_file, history_file)For cmd2 history command serialization, we could probably just serialize/deserialize the contents of self.history using the pickle module.