# HG changeset patch # User catherine@localhost # Date 1210969705 14400 # Node ID 354a6b713d365cc4ecabf9f1e9fd081e6f2638b4 # Parent 24fbec27d66f16b9dd40d98b8b5e4c3bb13781fb paste working! (linux) diff -r 24fbec27d66f -r 354a6b713d36 cmd2.py --- 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)