@@ -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 -----
@@ -4955,7 +4954,13 @@ def _persist_history(self) -> None:
49554954 except OSError as ex :
49564955 self .perror (f"Cannot write persistent history file '{ self .persistent_history_file } ': { ex } " )
49574956
4958- def _generate_transcript (self , history : Union [List [HistoryItem ], List [str ]], transcript_file : str ) -> None :
4957+ def _generate_transcript (
4958+ self ,
4959+ history : Union [List [HistoryItem ], List [str ]],
4960+ transcript_file : str ,
4961+ * ,
4962+ add_to_history : bool = True ,
4963+ ) -> None :
49594964 """Generate a transcript file from a given history of commands"""
49604965 self .last_result = False
49614966
@@ -5005,7 +5010,11 @@ def _generate_transcript(self, history: Union[List[HistoryItem], List[str]], tra
50055010
50065011 # then run the command and let the output go into our buffer
50075012 try :
5008- stop = self .onecmd_plus_hooks (history_item , raise_keyboard_interrupt = True )
5013+ stop = self .onecmd_plus_hooks (
5014+ history_item ,
5015+ add_to_history = add_to_history ,
5016+ raise_keyboard_interrupt = True ,
5017+ )
50095018 except KeyboardInterrupt as ex :
50105019 self .perror (ex )
50115020 stop = True
@@ -5149,9 +5158,17 @@ def do_run_script(self, args: argparse.Namespace) -> Optional[bool]:
51495158
51505159 if args .transcript :
51515160 # self.last_resort will be set by _generate_transcript()
5152- self ._generate_transcript (script_commands , os .path .expanduser (args .transcript ))
5161+ self ._generate_transcript (
5162+ script_commands ,
5163+ os .path .expanduser (args .transcript ),
5164+ add_to_history = self .save_scripted_commands ,
5165+ )
51535166 else :
5154- stop = self .runcmds_plus_hooks (script_commands , stop_on_keyboard_interrupt = True )
5167+ stop = self .runcmds_plus_hooks (
5168+ script_commands ,
5169+ add_to_history = self .save_scripted_commands ,
5170+ stop_on_keyboard_interrupt = True ,
5171+ )
51555172 self .last_result = True
51565173 return stop
51575174
0 commit comments