From 0fb81bea78232c8e688c678a8f94018db14bace2 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 11 Nov 2020 16:54:13 +0100 Subject: [PATCH] adding history to shell cli --- ereuse_devicehub/cli.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ereuse_devicehub/cli.py b/ereuse_devicehub/cli.py index b99c0b5e..4c253235 100644 --- a/ereuse_devicehub/cli.py +++ b/ereuse_devicehub/cli.py @@ -7,6 +7,27 @@ import flask.cli from ereuse_devicehub.config import DevicehubConfig from ereuse_devicehub.devicehub import Devicehub +import sys +sys.ps1 = '\001\033[92m\002>>> \001\033[0m\002' +sys.ps2= '\001\033[94m\002... \001\033[0m\002' + +import os, readline, rlcompleter, atexit +history_file = os.path.join(os.environ['HOME'], '.python_history') +try: + readline.read_history_file(history_file) +except IOError: + pass +readline.parse_and_bind("tab: complete") +readline.parse_and_bind('"\e[5~": history-search-backward') +readline.parse_and_bind('"\e[6~": history-search-forward') +readline.parse_and_bind('"\e[5C": forward-word') +readline.parse_and_bind('"\e[5D": backward-word') +readline.parse_and_bind('"\e\e[C": forward-word') +readline.parse_and_bind('"\e\e[D": backward-word') +readline.parse_and_bind('"\e[1;5C": forward-word') +readline.parse_and_bind('"\e[1;5D": backward-word') +readline.set_history_length(100000) +atexit.register(readline.write_history_file, history_file) class DevicehubGroup(flask.cli.FlaskGroup): # todo users cannot make cli to use a custom db this way!