@@ -4894,7 +4894,8 @@ def _persist_history(self) -> None:
4894
4894
except OSError as ex :
4895
4895
self .perror (f"Cannot write persistent history file '{ self .persistent_history_file } ': { ex } " )
4896
4896
4897
- def _generate_transcript (self , history : Union [List [HistoryItem ], List [str ]], transcript_file : str ) -> None :
4897
+ def _generate_transcript (self , history : Union [List [HistoryItem ], List [str ]], transcript_file : str ,
4898
+ add_to_history : bool = True ) -> None :
4898
4899
"""Generate a transcript file from a given history of commands"""
4899
4900
self .last_result = False
4900
4901
@@ -4944,7 +4945,8 @@ def _generate_transcript(self, history: Union[List[HistoryItem], List[str]], tra
4944
4945
4945
4946
# then run the command and let the output go into our buffer
4946
4947
try :
4947
- stop = self .onecmd_plus_hooks (history_item , raise_keyboard_interrupt = True )
4948
+ stop = self .onecmd_plus_hooks (history_item , raise_keyboard_interrupt = True ,
4949
+ add_to_history = add_to_history )
4948
4950
except KeyboardInterrupt as ex :
4949
4951
self .perror (ex )
4950
4952
stop = True
@@ -5045,6 +5047,11 @@ def _current_script_dir(self) -> Optional[str]:
5045
5047
help = 'record the output of the script as a transcript file' ,
5046
5048
completer = path_complete ,
5047
5049
)
5050
+ run_script_parser .add_argument (
5051
+ '--no-history' ,
5052
+ action = 'store_true' ,
5053
+ help = "Don't add commands issued by script to the history" ,
5054
+ )
5048
5055
run_script_parser .add_argument ('script_path' , help = "path to the script file" , completer = path_complete )
5049
5056
5050
5057
@with_argparser (run_script_parser )
@@ -5083,15 +5090,18 @@ def do_run_script(self, args: argparse.Namespace) -> Optional[bool]:
5083
5090
return None
5084
5091
5085
5092
orig_script_dir_count = len (self ._script_dir )
5093
+ add_to_history = not args .no_history
5086
5094
5087
5095
try :
5088
5096
self ._script_dir .append (os .path .dirname (expanded_path ))
5089
5097
5090
5098
if args .transcript :
5091
5099
# self.last_resort will be set by _generate_transcript()
5092
- self ._generate_transcript (script_commands , os .path .expanduser (args .transcript ))
5100
+ self ._generate_transcript (script_commands , os .path .expanduser (args .transcript ),
5101
+ add_to_history = add_to_history )
5093
5102
else :
5094
- stop = self .runcmds_plus_hooks (script_commands , stop_on_keyboard_interrupt = True )
5103
+ stop = self .runcmds_plus_hooks (script_commands , stop_on_keyboard_interrupt = True ,
5104
+ add_to_history = add_to_history )
5095
5105
self .last_result = True
5096
5106
return stop
5097
5107
0 commit comments