@@ -322,6 +322,7 @@ def __init__(
322
322
self .editor = Cmd .DEFAULT_EDITOR
323
323
self .feedback_to_output = False # Do not include nonessentials in >, | output by default (things like timing)
324
324
self .quiet = False # Do not suppress nonessential output
325
+ self .scripts_add_to_history = True # Scripts and pyscripts add commands to history
325
326
self .timing = False # Prints elapsed time for each command
326
327
327
328
# The maximum number of CompletionItems to display during tab completion. If the number of completion
@@ -1084,12 +1085,7 @@ def allow_style_type(value: str) -> ansi.AllowStyle:
1084
1085
)
1085
1086
1086
1087
self .add_settable (
1087
- Settable (
1088
- 'always_show_hint' ,
1089
- bool ,
1090
- 'Display tab completion hint even when completion suggestions print' ,
1091
- self ,
1092
- )
1088
+ Settable ('always_show_hint' , bool , 'Display tab completion hint even when completion suggestions print' , self )
1093
1089
)
1094
1090
self .add_settable (Settable ('debug' , bool , "Show full traceback on exception" , self ))
1095
1091
self .add_settable (Settable ('echo' , bool , "Echo command issued into output" , self ))
@@ -1099,6 +1095,7 @@ def allow_style_type(value: str) -> ansi.AllowStyle:
1099
1095
Settable ('max_completion_items' , int , "Maximum number of CompletionItems to display during tab completion" , self )
1100
1096
)
1101
1097
self .add_settable (Settable ('quiet' , bool , "Don't print nonessential feedback" , self ))
1098
+ self .add_settable (Settable ('scripts_add_to_history' , bool , 'Scripts and pyscripts add commands to history' , self ))
1102
1099
self .add_settable (Settable ('timing' , bool , "Report execution times" , self ))
1103
1100
1104
1101
# ----- Methods related to presenting output to the user -----
@@ -4459,7 +4456,8 @@ def py_quit() -> None:
4459
4456
PyBridge ,
4460
4457
)
4461
4458
4462
- py_bridge = PyBridge (self )
4459
+ add_to_history = self .scripts_add_to_history if pyscript else True
4460
+ py_bridge = PyBridge (self , add_to_history = add_to_history )
4463
4461
saved_sys_path = None
4464
4462
4465
4463
if self .in_pyscript ():
@@ -4955,7 +4953,13 @@ def _persist_history(self) -> None:
4955
4953
except OSError as ex :
4956
4954
self .perror (f"Cannot write persistent history file '{ self .persistent_history_file } ': { ex } " )
4957
4955
4958
- def _generate_transcript (self , history : Union [List [HistoryItem ], List [str ]], transcript_file : str ) -> None :
4956
+ def _generate_transcript (
4957
+ self ,
4958
+ history : Union [List [HistoryItem ], List [str ]],
4959
+ transcript_file : str ,
4960
+ * ,
4961
+ add_to_history : bool = True ,
4962
+ ) -> None :
4959
4963
"""Generate a transcript file from a given history of commands"""
4960
4964
self .last_result = False
4961
4965
@@ -5005,7 +5009,11 @@ def _generate_transcript(self, history: Union[List[HistoryItem], List[str]], tra
5005
5009
5006
5010
# then run the command and let the output go into our buffer
5007
5011
try :
5008
- stop = self .onecmd_plus_hooks (history_item , raise_keyboard_interrupt = True )
5012
+ stop = self .onecmd_plus_hooks (
5013
+ history_item ,
5014
+ add_to_history = add_to_history ,
5015
+ raise_keyboard_interrupt = True ,
5016
+ )
5009
5017
except KeyboardInterrupt as ex :
5010
5018
self .perror (ex )
5011
5019
stop = True
@@ -5149,9 +5157,17 @@ def do_run_script(self, args: argparse.Namespace) -> Optional[bool]:
5149
5157
5150
5158
if args .transcript :
5151
5159
# self.last_resort will be set by _generate_transcript()
5152
- self ._generate_transcript (script_commands , os .path .expanduser (args .transcript ))
5160
+ self ._generate_transcript (
5161
+ script_commands ,
5162
+ os .path .expanduser (args .transcript ),
5163
+ add_to_history = self .scripts_add_to_history ,
5164
+ )
5153
5165
else :
5154
- stop = self .runcmds_plus_hooks (script_commands , stop_on_keyboard_interrupt = True )
5166
+ stop = self .runcmds_plus_hooks (
5167
+ script_commands ,
5168
+ add_to_history = self .scripts_add_to_history ,
5169
+ stop_on_keyboard_interrupt = True ,
5170
+ )
5155
5171
self .last_result = True
5156
5172
return stop
5157
5173
0 commit comments