Mercurial > python-cmd2
diff cmd2.py @ 281:f4e8819a683a
hmm... missing my changes
author | catherine@cordelia |
---|---|
date | Thu, 08 Oct 2009 17:30:12 -0400 |
parents | 38198b11f48c |
children |
line wrap: on
line diff
--- a/cmd2.py Wed Oct 07 13:33:58 2009 -0400 +++ b/cmd2.py Thu Oct 08 17:30:12 2009 -0400 @@ -274,10 +274,15 @@ reserved_words = [] feedback_to_output = False quiet = False + all_defaults_to_shell = False settable = ['prompt', 'continuation_prompt', 'default_file_name', 'editor', - 'case_insensitive', 'feedback_to_output', 'quiet', 'echo', 'timing', - 'abbrev'] + 'case_insensitive', 'feedback_to_output', 'quiet', 'echo', + 'timing', 'abbrev', 'all_defaults_to_shell'] settable.sort() + if os.uname()[0] == 'Windows': + shell_commands = 'dir rename delete type'.split() + else: + shell_commands = 'ls pwd dir cat rm'.split() def poutput(self, msg): self.stdout.write(msg) @@ -664,7 +669,11 @@ self.lastcmd = statement.parsed.expanded funcname = self.func_named(statement.parsed.command) if not funcname: - return self.postparsing_postcmd(self.default(statement)) + if self.all_defaults_to_shell or ( + statement.parsed.command.lower() in self.shell_commands): + return self.postparsing_postcmd(self.do_shell(statement.parsed.raw)) + else: + return self.postparsing_postcmd(self.default(statement)) try: func = getattr(self, funcname) except AttributeError: @@ -935,10 +944,12 @@ fname = args.fname or self.default_file_name if args.idx == '*': saveme = '\n\n'.join(self.history[:]) - elif args.idx: - saveme = self.history[int(args.idx)-1] - else: - saveme = self.history[-1] + saveindex = (args.idx and int(args.idx)-1) or -1 + try: + saveme = self.history[saveindex] + except IndexError: + 'That command not found in the history (`hi` to review)' + return try: f = open(os.path.expanduser(fname), 'w') f.write(saveme)