diff cmd2.py @ 22:354a6b713d36

paste working! (linux)
author catherine@localhost
date Fri, 16 May 2008 16:28:25 -0400
parents 24fbec27d66f
children 37bff80ef816
line wrap: on
line diff
--- a/cmd2.py	Fri May 16 15:00:33 2008 -0400
+++ b/cmd2.py	Fri May 16 16:28:25 2008 -0400
@@ -18,7 +18,7 @@
 As of 0.3.0, options should be specified as `optparse` options.  See README.txt.
 flagReader.py options are still supported for backward compatibility
 """
-import cmd, re, os, sys, optparse
+import cmd, re, os, sys, optparse, subprocess
 from optparse import make_option
 
 class OptionParser(optparse.OptionParser):
@@ -112,8 +112,11 @@
         if mustBeTerminated and (parts[-2].strip()[-1] not in self.terminators):
             return statement, None
         (newStatement, redirect) = (symbol.join(parts[:-1]), parts[-1].strip())
-        if not self.legalFileName.search(redirect):
-            return statement, None
+        if redirect:
+            if not self.legalFileName.search(redirect):
+                return statement, None
+        else:
+            redirect = 1
         return newStatement, redirect
     
     def extractCommand(self, statement):
@@ -128,7 +131,7 @@
     def parseRedirectors(self, statement):
         mustBeTerminated = self.extractCommand(statement)[0] in self.multilineCommands
         newStatement, redirect = self.parseRedirector(statement, '>>', mustBeTerminated)
-        if redirect:
+        if redirect:            
             return newStatement, redirect, 'a'        
         newStatement, redirect = self.parseRedirector(statement, '>', mustBeTerminated)
         if redirect:
@@ -154,7 +157,17 @@
             statement = self.finishStatement(statement)
         statekeeper = None
         statement, redirect, mode = self.parseRedirectors(statement)
-        if redirect:
+        if redirect == 1:
+            if mode in ('a', 'r'):
+                clipcontents = subprocess.Popen('xclip -o -sel clip', shell=True, stdout=subprocess.PIPE).stdout.read()
+            if mode in ('w', 'a'):
+                statekeeper = Statekeeper(self, ('stdout',))
+                self.stdout = subprocess.Popen('xclip -sel clip', shell=True, stdin=subprocess.PIPE).stdin
+                if mode == 'a':
+                    self.stdout.write(clipcontents + '\n')
+            else:
+                statement = '%s %s' % (statement, clipcontents)
+        elif redirect:
             if mode in ('w','a'):
                 statekeeper = Statekeeper(self, ('stdout',))
                 self.stdout = open(redirect, mode)