@@ -322,6 +322,7 @@ def __init__(
322322 self .editor = Cmd .DEFAULT_EDITOR
323323 self .feedback_to_output = False # Do not include nonessentials in >, | output by default (things like timing)
324324 self .quiet = False # Do not suppress nonessential output
325+ self .scripts_add_to_history = True # Scripts and pyscripts add commands to history
325326 self .timing = False # Prints elapsed time for each command
326327
327328 # 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:
10841085 )
10851086
10861087 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 )
10931089 )
10941090 self .add_settable (Settable ('debug' , bool , "Show full traceback on exception" , self ))
10951091 self .add_settable (Settable ('echo' , bool , "Echo command issued into output" , self ))
@@ -1099,6 +1095,7 @@ def allow_style_type(value: str) -> ansi.AllowStyle:
10991095 Settable ('max_completion_items' , int , "Maximum number of CompletionItems to display during tab completion" , self )
11001096 )
11011097 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 ))
11021099 self .add_settable (Settable ('timing' , bool , "Report execution times" , self ))
11031100
11041101 # ----- Methods related to presenting output to the user -----
@@ -4459,7 +4456,8 @@ def py_quit() -> None:
44594456 PyBridge ,
44604457 )
44614458
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 )
44634461 saved_sys_path = None
44644462
44654463 if self .in_pyscript ():
@@ -4955,7 +4953,13 @@ def _persist_history(self) -> None:
49554953 except OSError as ex :
49564954 self .perror (f"Cannot write persistent history file '{ self .persistent_history_file } ': { ex } " )
49574955
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 :
49594963 """Generate a transcript file from a given history of commands"""
49604964 self .last_result = False
49614965
@@ -5005,7 +5009,11 @@ def _generate_transcript(self, history: Union[List[HistoryItem], List[str]], tra
50055009
50065010 # then run the command and let the output go into our buffer
50075011 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+ )
50095017 except KeyboardInterrupt as ex :
50105018 self .perror (ex )
50115019 stop = True
@@ -5149,9 +5157,17 @@ def do_run_script(self, args: argparse.Namespace) -> Optional[bool]:
51495157
51505158 if args .transcript :
51515159 # 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+ )
51535165 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+ )
51555171 self .last_result = True
51565172 return stop
51575173
0 commit comments