@@ -390,10 +390,10 @@ def __init__(self, completekey: str = 'tab', stdin=None, stdout=None, *,
390390 :param shortcuts: dictionary containing shortcuts for commands. If not supplied, then defaults to
391391 constants.DEFAULT_SHORTCUTS.
392392 """
393- # If use_ipython is False, make sure the do_ipy() method doesn 't exit
393+ # If use_ipython is False, make sure the ipy command isn 't available in this instance
394394 if not use_ipython :
395395 try :
396- del Cmd .do_ipy
396+ self .do_ipy = None
397397 except AttributeError :
398398 pass
399399
@@ -455,7 +455,7 @@ def __init__(self, completekey: str = 'tab', stdin=None, stdout=None, *,
455455 self ._initialize_history (persistent_history_file )
456456
457457 # Commands to exclude from the history command
458- self .exclude_from_history = '' 'history edit eof''' . split ()
458+ self .exclude_from_history = [ 'eof' , 'history' ]
459459
460460 # Dictionary of macro names and their values
461461 self .macros = dict ()
@@ -3542,14 +3542,9 @@ def do_history(self, args: argparse.Namespace) -> Optional[bool]:
35423542 else :
35433543 fobj .write ('{}\n ' .format (command .raw ))
35443544 try :
3545- # Handle potential edge case where the temp file needs to be quoted on the command line
3546- quoted_fname = utils .quote_string (fname )
3547-
3548- # noinspection PyTypeChecker
3549- self .do_edit (quoted_fname )
3550-
3545+ self ._run_editor (fname )
35513546 # noinspection PyTypeChecker
3552- self .do_run_script (quoted_fname )
3547+ self .do_run_script (utils . quote_string ( fname ) )
35533548 finally :
35543549 os .remove (fname )
35553550 elif args .output_file :
@@ -3741,25 +3736,33 @@ def _generate_transcript(self, history: List[Union[HistoryItem, str]], transcrip
37413736 msg = '{} {} saved to transcript file {!r}'
37423737 self .pfeedback (msg .format (commands_run , plural , transcript_file ))
37433738
3744- edit_description = ("Edit a file in a text editor \n "
3739+ edit_description = ("Run a text editor and optionally open a file with it \n "
37453740 "\n "
37463741 "The editor used is determined by a settable parameter. To set it:\n "
37473742 "\n "
37483743 " set editor (program-name)" )
37493744
37503745 edit_parser = Cmd2ArgumentParser (description = edit_description )
37513746 edit_parser .add_argument ('file_path' , nargs = argparse .OPTIONAL ,
3752- help = "path to a file to open in editor" , completer_method = path_complete )
3747+ help = "optional path to a file to open in editor" , completer_method = path_complete )
37533748
37543749 @with_argparser (edit_parser )
37553750 def do_edit (self , args : argparse .Namespace ) -> None :
3756- """Edit a file in a text editor"""
3751+ """Run a text editor and optionally open a file with it"""
3752+ self ._run_editor (args .file_path )
3753+
3754+ def _run_editor (self , file_path : Optional [str ]) -> None :
3755+ """
3756+ Run a text editor and optionally open a file with it
3757+ :param file_path: optional path of the file to edit
3758+ :raises EnvironmentError if self.editor is not set
3759+ """
37573760 if not self .editor :
37583761 raise EnvironmentError ("Please use 'set editor' to specify your text editing program of choice." )
37593762
37603763 command = utils .quote_string (os .path .expanduser (self .editor ))
3761- if args . file_path :
3762- command += " " + utils .quote_string (os .path .expanduser (args . file_path ))
3764+ if file_path :
3765+ command += " " + utils .quote_string (os .path .expanduser (file_path ))
37633766
37643767 # noinspection PyTypeChecker
37653768 self .do_shell (command )
0 commit comments