From 71d7465c570ea98f6df4ca6b4e88f10c77f4eba0 Mon Sep 17 00:00:00 2001 From: Todd Leonhardt Date: Sat, 4 Feb 2017 12:37:38 -0500 Subject: Added more and better unit tests for load and save commands --- cmd2.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'cmd2.py') diff --git a/cmd2.py b/cmd2.py index 85f9b752..537c28b1 100755 --- a/cmd2.py +++ b/cmd2.py @@ -531,7 +531,8 @@ class Cmd(cmd.Cmd): if sys.platform[:3] == 'win': editor = 'notepad' else: - for editor in ['gedit', 'kate', 'vim', 'vi', 'emacs', 'nano', 'pico']: + # Favor command-line editors first so we don't leave the terminal to edit + for editor in ['vim', 'vi', 'emacs', 'nano', 'pico', 'gedit', 'kate', 'subl', 'geany', 'atom']: if _which(editor): break @@ -1332,7 +1333,8 @@ class Cmd(cmd.Cmd): elif args.idx: saveme = self.history[int(args.idx) - 1] else: - saveme = self.history[-1] + # Since this save command has already been added to history, need to go one more back for previous + saveme = self.history[-2] try: f = open(os.path.expanduser(fname), 'w') f.write(saveme) @@ -1374,7 +1376,8 @@ class Cmd(cmd.Cmd): def do_load(self, arg=None): """Runs script of command(s) from a file or URL.""" - if arg is None: + # If arg is None or arg is an empty string, use the default filename + if not arg: targetname = self.default_file_name else: arg = arg.split(None, 1) -- cgit v1.2.1