From d5efa8728846e1866fdfd4d9f3d1c0d877a9a821 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Thu, 12 Oct 2017 14:15:36 -0400 Subject: [PATCH] Add history to the dbg cli helper As long as we are adding readline, history persistence is also really handy. --- confluent_server/dbgtools/confluentdbgcli.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/confluent_server/dbgtools/confluentdbgcli.py b/confluent_server/dbgtools/confluentdbgcli.py index 04ba8783..94c1ab82 100644 --- a/confluent_server/dbgtools/confluentdbgcli.py +++ b/confluent_server/dbgtools/confluentdbgcli.py @@ -19,12 +19,28 @@ # Note that this script has a high chance of breaking confluent, so # do not be surprised if confluent crashes as you exit... +import atexit +import os import select import socket import readline import sys import threading +historypath = os.path.expanduser("~/.confluentdbghistory") + +def save_history(): + import readline + try: + readline.write_history_file(historypath) + except: + pass + +if os.path.exists(historypath): + readline.set_history_length(1000) + readline.read_history_file(historypath) + +atexit.register(save_history) readline.parse_and_bind('tab: complete') conn = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) conn.connect('/var/run/confluent/dbg.sock')