Mercurial > python-cmd2
comparison cmd2.py @ 281:f4e8819a683a
hmm... missing my changes
author | catherine@cordelia |
---|---|
date | Thu, 08 Oct 2009 17:30:12 -0400 |
parents | 38198b11f48c |
children |
comparison
equal
deleted
inserted
replaced
280:38198b11f48c | 281:f4e8819a683a |
---|---|
272 nonpythoncommand = 'cmd' | 272 nonpythoncommand = 'cmd' |
273 current_script_dir = None | 273 current_script_dir = None |
274 reserved_words = [] | 274 reserved_words = [] |
275 feedback_to_output = False | 275 feedback_to_output = False |
276 quiet = False | 276 quiet = False |
277 all_defaults_to_shell = False | |
277 settable = ['prompt', 'continuation_prompt', 'default_file_name', 'editor', | 278 settable = ['prompt', 'continuation_prompt', 'default_file_name', 'editor', |
278 'case_insensitive', 'feedback_to_output', 'quiet', 'echo', 'timing', | 279 'case_insensitive', 'feedback_to_output', 'quiet', 'echo', |
279 'abbrev'] | 280 'timing', 'abbrev', 'all_defaults_to_shell'] |
280 settable.sort() | 281 settable.sort() |
282 if os.uname()[0] == 'Windows': | |
283 shell_commands = 'dir rename delete type'.split() | |
284 else: | |
285 shell_commands = 'ls pwd dir cat rm'.split() | |
281 | 286 |
282 def poutput(self, msg): | 287 def poutput(self, msg): |
283 self.stdout.write(msg) | 288 self.stdout.write(msg) |
284 if msg[-1] != '\n': | 289 if msg[-1] != '\n': |
285 self.stdout.write('\n') | 290 self.stdout.write('\n') |
662 try: | 667 try: |
663 # "heart" of the command, replace's cmd's onecmd() | 668 # "heart" of the command, replace's cmd's onecmd() |
664 self.lastcmd = statement.parsed.expanded | 669 self.lastcmd = statement.parsed.expanded |
665 funcname = self.func_named(statement.parsed.command) | 670 funcname = self.func_named(statement.parsed.command) |
666 if not funcname: | 671 if not funcname: |
667 return self.postparsing_postcmd(self.default(statement)) | 672 if self.all_defaults_to_shell or ( |
673 statement.parsed.command.lower() in self.shell_commands): | |
674 return self.postparsing_postcmd(self.do_shell(statement.parsed.raw)) | |
675 else: | |
676 return self.postparsing_postcmd(self.default(statement)) | |
668 try: | 677 try: |
669 func = getattr(self, funcname) | 678 func = getattr(self, funcname) |
670 except AttributeError: | 679 except AttributeError: |
671 return self.postparsing_postcmd(self.default(statement)) | 680 return self.postparsing_postcmd(self.default(statement)) |
672 timestart = datetime.datetime.now() | 681 timestart = datetime.datetime.now() |
933 self.perror(self.do_save.__doc__) | 942 self.perror(self.do_save.__doc__) |
934 return | 943 return |
935 fname = args.fname or self.default_file_name | 944 fname = args.fname or self.default_file_name |
936 if args.idx == '*': | 945 if args.idx == '*': |
937 saveme = '\n\n'.join(self.history[:]) | 946 saveme = '\n\n'.join(self.history[:]) |
938 elif args.idx: | 947 saveindex = (args.idx and int(args.idx)-1) or -1 |
939 saveme = self.history[int(args.idx)-1] | 948 try: |
940 else: | 949 saveme = self.history[saveindex] |
941 saveme = self.history[-1] | 950 except IndexError: |
951 'That command not found in the history (`hi` to review)' | |
952 return | |
942 try: | 953 try: |
943 f = open(os.path.expanduser(fname), 'w') | 954 f = open(os.path.expanduser(fname), 'w') |
944 f.write(saveme) | 955 f.write(saveme) |
945 f.close() | 956 f.close() |
946 self.pfeedback('Saved to %s' % (fname)) | 957 self.pfeedback('Saved to %s' % (fname)) |