From 769c3a908890a15c8f5e08cd651e1120194c2e74 Mon Sep 17 00:00:00 2001 From: Devendra Date: Sat, 26 Apr 2014 00:23:30 +0530 Subject: save history to file --- python/examples/console.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'python/examples') diff --git a/python/examples/console.py b/python/examples/console.py index 225c7eb..8a3ab3b 100644 --- a/python/examples/console.py +++ b/python/examples/console.py @@ -14,6 +14,22 @@ from cmd2 import Cmd, make_option, options, Cmd2TestCase import optparse import json +import atexit +import os +import readline +import rlcompleter + +historyPath = os.path.expanduser("~/.pubnub_console_history") + +def save_history(historyPath=historyPath): + import readline + readline.write_history_file(historyPath) + +if os.path.exists(historyPath): + readline.read_history_file(historyPath) + +atexit.register(save_history) + of=sys.stdout color = Cmd() -- cgit v1.2.3