changeset 50:dccf27f52f51

unifying pipe and redirect
author catherine@localhost
date Mon, 09 Jun 2008 10:05:25 -0400
parents 8926b72d828e
children 26e33f64f68e
files cmd2.py
diffstat 1 files changed, 7 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/cmd2.py	Fri Jun 06 16:51:09 2008 -0400
+++ b/cmd2.py	Mon Jun 09 10:05:25 2008 -0400
@@ -234,7 +234,7 @@
 
         """
         command, args = self.extractCommand(line)
-        statement = ' '.join([command, args])
+        statement = originalStatement = ' '.join([command, args])
         if (not assumeComplete) and (command in self.multilineCommands):
             statement = self.finishStatement(statement)
         statekeeper = None
@@ -246,9 +246,11 @@
             self.stdout = redirect.stdin
             stop = cmd.Cmd.onecmd(self, statement)
             statekeeper.restore()            
-            for result in redirect.communicate():
+            for result in redirect.communicate():              
                 self.stdout.write(result or '')
-            return stop # didn't record in history
+            if command not in self.excludeFromHistory:
+                self.history.append(originalStatement)                  
+            return stop 
         else:
             statement, redirect, mode = self.parseRedirectors(statement)
             if redirect == self._TO_PASTE_BUFFER:
@@ -273,7 +275,7 @@
         stop = cmd.Cmd.onecmd(self, statement)
         try:
             if command not in self.excludeFromHistory:
-                self.history.append(statement) # or should we append the unmodified statement?
+                self.history.append(originalStatement)
         finally:
             if statekeeper:
                 if redirect == self._TO_PASTE_BUFFER:
@@ -288,6 +290,7 @@
         #import pdb; pdb.set_trace()
         return bool(self.statementEndPattern.search(lines)) \
                or lines[-3:] == 'EOF' \
+               or self.findPipe(lines)[1] \
                or self.parseRedirectors(lines)[1]
     
     def finishStatement(self, firstline):