Mercurial > python-cmd2
diff cmd2.py @ 47:927bc07467de
fixed misfind of editor
author | catherine@cordelia |
---|---|
date | Tue, 03 Jun 2008 15:04:40 -0400 |
parents | 27b45b33a574 |
children | 34fb41095451 |
line wrap: on
line diff
--- a/cmd2.py Tue Jun 03 08:01:16 2008 -0400 +++ b/cmd2.py Tue Jun 03 15:04:40 2008 -0400 @@ -129,7 +129,7 @@ multilineCommands = [] continuationPrompt = '> ' shortcuts = {'?': 'help', '!': 'shell', '@': 'load'} - excludeFromHistory = '''run r list l history hi ed li eof'''.split() + excludeFromHistory = '''run r list l history hi ed edit li eof'''.split() defaultExtension = 'txt' defaultFileName = 'command.txt' editor = os.environ.get('EDITOR') @@ -139,7 +139,7 @@ editor = 'notepad' else: for editor in ['gedit', 'kate', 'vim', 'emacs', 'nano', 'pico']: - if os.system('which %s' % (editor)): + if not os.system('which %s' % (editor)): break settable = ['prompt', 'continuationPrompt', 'defaultFileName', 'editor', 'caseInsensitive'] @@ -180,7 +180,7 @@ pipeFinder = notAPipe + '|' + pyparsing.SkipTo(pyparsing.StringEnd()) def findPipe(self, statement): try: - statement, pipe, destination = pipeFinder.parseString(statement) + statement, pipe, destination = self.pipeFinder.parseString(statement) return statement, destination except pyparsing.ParseException: return statement, None @@ -239,11 +239,13 @@ statement = self.finishStatement(statement) statekeeper = None stop = 0 - statement, redirect = self.pipeFinder(statement) + statement, redirect = self.findPipe(statement) if redirect: + statekeeper = Statekeeper(self, ('stdout',)) redirect = subprocess.Popen(redirect, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE) - redirect.stdin = self.stdout + self.stdout = redirect.stdin stop = cmd.Cmd.onecmd(self, statement) + statekeeper.restore() self.stdout.write(redirect.stdout.read()) return stop # didn't record in history else: