summaryrefslogtreecommitdiff
path: root/cmd2/cmd2.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2018-05-23 23:55:36 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2018-05-23 23:55:36 -0400
commit26743054028cddde1d148f23e897a7a3661ee88c (patch)
tree2f7ccbc64c75ee18cf78f61647ab4425a130a250 /cmd2/cmd2.py
parent24aa66f1101d8ede2bbd8ae3a79d20cb398b1eec (diff)
downloadcmd2-git-26743054028cddde1d148f23e897a7a3661ee88c.tar.gz
Clearing py's history before rebuilding it
Diffstat (limited to 'cmd2/cmd2.py')
-rw-r--r--cmd2/cmd2.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index 4359ef12..a534f2a1 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -2508,7 +2508,6 @@ Usage: Usage: unalias [-a] name [name ...]
index_dict = {1: self.shell_cmd_complete}
return self.index_based_complete(text, line, begidx, endidx, index_dict, self.path_complete)
- # noinspection PyBroadException
def do_py(self, arg):
"""
Invoke python command, shell, or script
@@ -2525,6 +2524,7 @@ Usage: Usage: unalias [-a] name [name ...]
return
self._in_py = True
+ # noinspection PyBroadException
try:
arg = arg.strip()
@@ -2581,12 +2581,11 @@ Usage: Usage: unalias [-a] name [name ...]
for i in range(1, readline.get_current_history_length() + 1):
saved_cmd2_history.append(readline.get_history_item(i))
- # Keep a list of commands run in the Python console
- # noinspection PyAttributeOutsideInit
- self.py_history = getattr(self, 'py_history', [])
+ readline.clear_history()
# Restore py's history
- readline.clear_history()
+ # noinspection PyAttributeOutsideInit
+ self.py_history = getattr(self, 'py_history', [])
for item in self.py_history:
readline.add_history(item)
@@ -2639,11 +2638,14 @@ Usage: Usage: unalias [-a] name [name ...]
if rl_type != RlType.NONE:
# Save py's history
+ # noinspection PyAttributeOutsideInit
+ self.py_history = []
for i in range(1, readline.get_current_history_length() + 1):
self.py_history.append(readline.get_history_item(i))
- # Restore cmd2's history
readline.clear_history()
+
+ # Restore cmd2's history
for item in saved_cmd2_history:
readline.add_history(item)