@@ -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 .save_scripted_commands = True # Save commands run in scripts and pyscripts 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,9 @@ 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 (
1099+ Settable ('save_scripted_commands' , bool , 'Save commands run in scripts and pyscripts to history' , self )
1100+ )
11021101 self .add_settable (Settable ('timing' , bool , "Report execution times" , self ))
11031102
11041103 # ----- Methods related to presenting output to the user -----
@@ -4459,7 +4458,8 @@ def py_quit() -> None:
44594458 PyBridge ,
44604459 )
44614460
4462- py_bridge = PyBridge (self )
4461+ add_to_history = self .save_scripted_commands if pyscript else True
4462+ py_bridge = PyBridge (self , add_to_history = add_to_history )
44634463 saved_sys_path = None
44644464
44654465 if self .in_pyscript ():
@@ -4955,7 +4955,13 @@ def _persist_history(self) -> None:
49554955 except OSError as ex :
49564956 self .perror (f"Cannot write persistent history file '{ self .persistent_history_file } ': { ex } " )
49574957
4958- def _generate_transcript (self , history : Union [List [HistoryItem ], List [str ]], transcript_file : str ) -> None :
4958+ def _generate_transcript (
4959+ self ,
4960+ history : Union [List [HistoryItem ], List [str ]],
4961+ transcript_file : str ,
4962+ * ,
4963+ add_to_history : bool = True ,
4964+ ) -> None :
49594965 """Generate a transcript file from a given history of commands"""
49604966 self .last_result = False
49614967
@@ -5005,7 +5011,11 @@ def _generate_transcript(self, history: Union[List[HistoryItem], List[str]], tra
50055011
50065012 # then run the command and let the output go into our buffer
50075013 try :
5008- stop = self .onecmd_plus_hooks (history_item , raise_keyboard_interrupt = True )
5014+ stop = self .onecmd_plus_hooks (
5015+ history_item ,
5016+ add_to_history = add_to_history ,
5017+ raise_keyboard_interrupt = True ,
5018+ )
50095019 except KeyboardInterrupt as ex :
50105020 self .perror (ex )
50115021 stop = True
@@ -5149,9 +5159,17 @@ def do_run_script(self, args: argparse.Namespace) -> Optional[bool]:
51495159
51505160 if args .transcript :
51515161 # self.last_resort will be set by _generate_transcript()
5152- self ._generate_transcript (script_commands , os .path .expanduser (args .transcript ))
5162+ self ._generate_transcript (
5163+ script_commands ,
5164+ os .path .expanduser (args .transcript ),
5165+ add_to_history = self .save_scripted_commands ,
5166+ )
51535167 else :
5154- stop = self .runcmds_plus_hooks (script_commands , stop_on_keyboard_interrupt = True )
5168+ stop = self .runcmds_plus_hooks (
5169+ script_commands ,
5170+ add_to_history = self .save_scripted_commands ,
5171+ stop_on_keyboard_interrupt = True ,
5172+ )
51555173 self .last_result = True
51565174 return stop
51575175
0 commit comments