@@ -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 -----
@@ -2755,9 +2754,10 @@ def combine_rl_history(statement: Statement) -> None:
2755
2754
# terminator
2756
2755
nextline = '\n '
2757
2756
self .poutput (nextline )
2757
+
2758
2758
line = f'{ self ._multiline_in_progress } { nextline } '
2759
2759
2760
- # Combine all lines of this multiline command as we go.
2760
+ # Combine all history lines of this multiline command as we go.
2761
2761
if nextline :
2762
2762
statement = self .statement_parser .parse_command_only (line )
2763
2763
combine_rl_history (statement )
@@ -4950,7 +4950,13 @@ def _persist_history(self) -> None:
4950
4950
except OSError as ex :
4951
4951
self .perror (f"Cannot write persistent history file '{ self .persistent_history_file } ': { ex } " )
4952
4952
4953
- def _generate_transcript (self , history : Union [List [HistoryItem ], List [str ]], transcript_file : str ) -> None :
4953
+ def _generate_transcript (
4954
+ self ,
4955
+ history : Union [List [HistoryItem ], List [str ]],
4956
+ transcript_file : str ,
4957
+ * ,
4958
+ add_to_history : bool = True ,
4959
+ ) -> None :
4954
4960
"""Generate a transcript file from a given history of commands"""
4955
4961
self .last_result = False
4956
4962
@@ -5000,7 +5006,11 @@ def _generate_transcript(self, history: Union[List[HistoryItem], List[str]], tra
5000
5006
5001
5007
# then run the command and let the output go into our buffer
5002
5008
try :
5003
- stop = self .onecmd_plus_hooks (history_item , raise_keyboard_interrupt = True )
5009
+ stop = self .onecmd_plus_hooks (
5010
+ history_item ,
5011
+ add_to_history = add_to_history ,
5012
+ raise_keyboard_interrupt = True ,
5013
+ )
5004
5014
except KeyboardInterrupt as ex :
5005
5015
self .perror (ex )
5006
5016
stop = True
@@ -5144,9 +5154,17 @@ def do_run_script(self, args: argparse.Namespace) -> Optional[bool]:
5144
5154
5145
5155
if args .transcript :
5146
5156
# self.last_resort will be set by _generate_transcript()
5147
- self ._generate_transcript (script_commands , os .path .expanduser (args .transcript ))
5157
+ self ._generate_transcript (
5158
+ script_commands ,
5159
+ os .path .expanduser (args .transcript ),
5160
+ add_to_history = self .save_scripted_commands ,
5161
+ )
5148
5162
else :
5149
- stop = self .runcmds_plus_hooks (script_commands , stop_on_keyboard_interrupt = True )
5163
+ stop = self .runcmds_plus_hooks (
5164
+ script_commands ,
5165
+ add_to_history = self .save_scripted_commands ,
5166
+ stop_on_keyboard_interrupt = True ,
5167
+ )
5150
5168
self .last_result = True
5151
5169
return stop
5152
5170
0 commit comments