# HG changeset patch # User catherine@cordelia # Date 1255037412 14400 # Node ID f4e8819a683a8fb243b754ad382edf8d8b55f40d # Parent 38198b11f48c7f113f6301d9f4b44e694a42c205 hmm... missing my changes diff -r 38198b11f48c -r f4e8819a683a cmd2.py --- 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)