@@ -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 .save_scripted_commands = True # Save commands run in scripts and pyscripts 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,9 @@ 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 (
1099
+ Settable ('save_scripted_commands' , bool , 'Save commands run in scripts and pyscripts to history' , self )
1100
+ )
1102
1101
self .add_settable (Settable ('timing' , bool , "Report execution times" , self ))
1103
1102
1104
1103
# ----- Methods related to presenting output to the user -----
@@ -4950,7 +4949,13 @@ def _persist_history(self) -> None:
4950
4949
except OSError as ex :
4951
4950
self .perror (f"Cannot write persistent history file '{ self .persistent_history_file } ': { ex } " )
4952
4951
4953
- def _generate_transcript (self , history : Union [List [HistoryItem ], List [str ]], transcript_file : str ) -> None :
4952
+ def _generate_transcript (
4953
+ self ,
4954
+ history : Union [List [HistoryItem ], List [str ]],
4955
+ transcript_file : str ,
4956
+ * ,
4957
+ add_to_history : bool = True ,
4958
+ ) -> None :
4954
4959
"""Generate a transcript file from a given history of commands"""
4955
4960
self .last_result = False
4956
4961
@@ -5000,7 +5005,11 @@ def _generate_transcript(self, history: Union[List[HistoryItem], List[str]], tra
5000
5005
5001
5006
# then run the command and let the output go into our buffer
5002
5007
try :
5003
- stop = self .onecmd_plus_hooks (history_item , raise_keyboard_interrupt = True )
5008
+ stop = self .onecmd_plus_hooks (
5009
+ history_item ,
5010
+ add_to_history = add_to_history ,
5011
+ raise_keyboard_interrupt = True ,
5012
+ )
5004
5013
except KeyboardInterrupt as ex :
5005
5014
self .perror (ex )
5006
5015
stop = True
@@ -5144,9 +5153,17 @@ def do_run_script(self, args: argparse.Namespace) -> Optional[bool]:
5144
5153
5145
5154
if args .transcript :
5146
5155
# self.last_resort will be set by _generate_transcript()
5147
- self ._generate_transcript (script_commands , os .path .expanduser (args .transcript ))
5156
+ self ._generate_transcript (
5157
+ script_commands ,
5158
+ os .path .expanduser (args .transcript ),
5159
+ add_to_history = self .save_scripted_commands ,
5160
+ )
5148
5161
else :
5149
- stop = self .runcmds_plus_hooks (script_commands , stop_on_keyboard_interrupt = True )
5162
+ stop = self .runcmds_plus_hooks (
5163
+ script_commands ,
5164
+ add_to_history = self .save_scripted_commands ,
5165
+ stop_on_keyboard_interrupt = True ,
5166
+ )
5150
5167
self .last_result = True
5151
5168
return stop
5152
5169
0 commit comments