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