cmd2
cmd2 copied to clipboard
Persistent history file not saved when application is killed
When killing the Cmd2 application (e.g. by closing the terminal window), persistent history file is not saved.
By using persistent_history_file argument for Cmd.init(), and hitting quit command, I can see the persistent history command is updated as expected.
Environment : Ubuntu 22 on WLS2
I checked the behavior of bash and ipython. They save history persistently even when I close terminal window.
As a hacky solution, I was able to use _persist_history() private method in postcmd_hook to save command history immediately after all command executions.
def __init__(self):
:
self.register_postcmd_hook(self.on_command_executed)
:
def on_command_executed(self, data: cmd2.plugin.PostcommandData) -> cmd2.plugin.PostcommandData:
# Save command history immediately
self._persist_history()
return data