Skip to content

Consider adding optional persistent history #265

@tleonhardt

Description

@tleonhardt

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions