@@ -433,7 +433,7 @@ def __init__(self, completekey: str = 'tab', stdin=None, stdout=None, *,
433433 self ._initialize_history (persistent_history_file )
434434
435435 # Commands to exclude from the history command
436- self .exclude_from_history = '' 'history edit eof''' . split ()
436+ self .exclude_from_history = [ 'eof' , 'history' ]
437437
438438 # Dictionary of macro names and their values
439439 self .macros = dict ()
@@ -3520,14 +3520,9 @@ def do_history(self, args: argparse.Namespace) -> Optional[bool]:
35203520 else :
35213521 fobj .write ('{}\n ' .format (command .raw ))
35223522 try :
3523- # Handle potential edge case where the temp file needs to be quoted on the command line
3524- quoted_fname = utils .quote_string (fname )
3525-
3526- # noinspection PyTypeChecker
3527- self .do_edit (quoted_fname )
3528-
3523+ self ._run_editor (fname )
35293524 # noinspection PyTypeChecker
3530- self .do_run_script (quoted_fname )
3525+ self .do_run_script (utils . quote_string ( fname ) )
35313526 finally :
35323527 os .remove (fname )
35333528 elif args .output_file :
@@ -3719,25 +3714,33 @@ def _generate_transcript(self, history: List[Union[HistoryItem, str]], transcrip
37193714 msg = '{} {} saved to transcript file {!r}'
37203715 self .pfeedback (msg .format (commands_run , plural , transcript_file ))
37213716
3722- edit_description = ("Edit a file in a text editor \n "
3717+ edit_description = ("Run a text editor and optionally open a file with it \n "
37233718 "\n "
37243719 "The editor used is determined by a settable parameter. To set it:\n "
37253720 "\n "
37263721 " set editor (program-name)" )
37273722
37283723 edit_parser = Cmd2ArgumentParser (description = edit_description )
37293724 edit_parser .add_argument ('file_path' , nargs = argparse .OPTIONAL ,
3730- help = "path to a file to open in editor" , completer_method = path_complete )
3725+ help = "optional path to a file to open in editor" , completer_method = path_complete )
37313726
37323727 @with_argparser (edit_parser )
37333728 def do_edit (self , args : argparse .Namespace ) -> None :
3734- """Edit a file in a text editor"""
3729+ """Run a text editor and optionally open a file with it"""
3730+ self ._run_editor (args .file_path )
3731+
3732+ def _run_editor (self , file_path : Optional [str ]) -> None :
3733+ """
3734+ Run a text editor and optionally open a file with it
3735+ :param file_path: optional path of the file to edit
3736+ :raises EnvironmentError if self.editor is not set
3737+ """
37353738 if not self .editor :
37363739 raise EnvironmentError ("Please use 'set editor' to specify your text editing program of choice." )
37373740
37383741 command = utils .quote_string (os .path .expanduser (self .editor ))
3739- if args . file_path :
3740- command += " " + utils .quote_string (os .path .expanduser (args . file_path ))
3742+ if file_path :
3743+ command += " " + utils .quote_string (os .path .expanduser (file_path ))
37413744
37423745 # noinspection PyTypeChecker
37433746 self .do_shell (command )
0 commit comments