comparison cmd2.py @ 83:2176ce847939

merged copy to both clipboards in
author catherine@Elli.myhome.westell.com
date Sun, 13 Jul 2008 07:51:02 -0400
parents bbf0afc6868b
children 416ea36af789
comparison
equal deleted inserted replaced
82:bbf0afc6868b 83:2176ce847939
117 return xclipproc.stdout.read() 117 return xclipproc.stdout.read()
118 def writeToPasteBuffer(txt): 118 def writeToPasteBuffer(txt):
119 xclipproc = subprocess.Popen('xclip -sel clip', shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE) 119 xclipproc = subprocess.Popen('xclip -sel clip', shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
120 xclipproc.stdin.write(txt) 120 xclipproc.stdin.write(txt)
121 xclipproc.stdin.close() 121 xclipproc.stdin.close()
122 # but we want it in both the "primary" and "mouse" clipboards
123 xclipproc = subprocess.Popen('xclip', shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
124 xclipproc.stdin.write(txt)
125 xclipproc.stdin.close()
122 else: 126 else:
123 def getPasteBuffer(): 127 def getPasteBuffer():
124 raise OSError, pastebufferr % ('xclip', 'On Debian/Ubuntu, install with "sudo apt-get install xclip"') 128 raise OSError, pastebufferr % ('xclip', 'On Debian/Ubuntu, install with "sudo apt-get install xclip"')
125 setPasteBuffer = getPasteBuffer 129 setPasteBuffer = getPasteBuffer
126 130
153 for editor in ['gedit', 'kate', 'vim', 'emacs', 'nano', 'pico']: 157 for editor in ['gedit', 'kate', 'vim', 'emacs', 'nano', 'pico']:
154 if not os.system('which %s' % (editor)): 158 if not os.system('which %s' % (editor)):
155 break 159 break
156 160
157 settable = ['prompt', 'continuationPrompt', 'defaultFileName', 'editor', 'caseInsensitive'] 161 settable = ['prompt', 'continuationPrompt', 'defaultFileName', 'editor', 'caseInsensitive']
158 terminators = ';\n' #TODO: strip this
159 _TO_PASTE_BUFFER = 1 162 _TO_PASTE_BUFFER = 1
160 def do_cmdenvironment(self, args): 163 def do_cmdenvironment(self, args):
161 self.stdout.write(""" 164 self.stdout.write("""
162 Commands are %(casesensitive)scase-sensitive. 165 Commands are %(casesensitive)scase-sensitive.
163 Commands may be terminated with: %(terminators)s 166 Commands may be terminated with: %(terminators)s
164 Settable parameters: %(settable)s 167 Settable parameters: %(settable)s
165 """ % 168 """ %
166 { 'casesensitive': ('not ' and self.caseInsensitive) or '', 169 { 'casesensitive': ('not ' and self.caseInsensitive) or '',
167 'terminators': ' '.join(self.terminators), 170 'terminators': self.terminatorPattern,
168 'settable': ' '.join(self.settable) 171 'settable': ' '.join(self.settable)
169 }) 172 })
170 173
171 def do_help(self, arg): 174 def do_help(self, arg):
172 cmd.Cmd.do_help(self, arg) 175 cmd.Cmd.do_help(self, arg)
224 ('got from ', '<', 'thisfile.txt') 227 ('got from ', '<', 'thisfile.txt')
225 ''' 228 '''
226 if isinstance(s, pyparsing.ParseResults): 229 if isinstance(s, pyparsing.ParseResults):
227 return s 230 return s
228 result = (pyparsing.SkipTo(pyparsing.StringEnd()))('fullStatement').parseString(s) 231 result = (pyparsing.SkipTo(pyparsing.StringEnd()))('fullStatement').parseString(s)
229 result['statement'] = result.fullStatement 232 if s[0] in self.shortcuts:
230 result['parseable'] = result.fullStatement 233 s = self.shortcuts[s[0]] + ' ' + s[1:]
234 result['statement'] = s
235 result['parseable'] = s
231 result += parseSearchResults(self.terminatorPattern, s) 236 result += parseSearchResults(self.terminatorPattern, s)
232 if result.terminator: 237 if result.terminator:
233 result['statement'] = result.upToIncluding 238 result['statement'] = result.upToIncluding
239 result['unterminated'] = result.before
234 result['parseable'] = result.after 240 result['parseable'] = result.after
235 else: 241 else:
236 result += parseSearchResults(self.punctuationPattern, s) 242 result += parseSearchResults(self.punctuationPattern, s)
237 result['statement'] = result.before 243 result['statement'] = result['unterminated'] = result.before
238 result += parseSearchResults(self.pipePattern, result.parseable) 244 result += parseSearchResults(self.pipePattern, result.parseable)
239 result += parseSearchResults(self.redirectInPattern, result.parseable) 245 result += parseSearchResults(self.redirectInPattern, result.parseable)
240 result += parseSearchResults(self.redirectOutPattern, result.parseable) 246 result += parseSearchResults(self.redirectOutPattern, result.parseable)
241 result += parseSearchResults(self.argSeparatorPattern, result.statement) 247 result += parseSearchResults(self.argSeparatorPattern, result.statement)
242 if self.caseInsensitive: 248 if self.caseInsensitive:
261 see the precmd() and postcmd() methods for useful execution hooks. 267 see the precmd() and postcmd() methods for useful execution hooks.
262 The return value is a flag indicating whether interpretation of 268 The return value is a flag indicating whether interpretation of
263 commands by the interpreter should stop. 269 commands by the interpreter should stop.
264 270
265 """ 271 """
272 line = line.strip()
273 if not line:
274 return
266 statement = self.parsed(line) 275 statement = self.parsed(line)
267 while (statement.command in self.multilineCommands) and not \ 276 while (statement.command in self.multilineCommands) and not \
268 (statement.terminator or assumeComplete): 277 (statement.terminator or assumeComplete):
269 statement = self.parsed('%s\n%s' % (statement.fullStatement, 278 statement = self.parsed('%s\n%s' % (statement.fullStatement,
270 self.pseudo_raw_input(self.continuationPrompt))) 279 self.pseudo_raw_input(self.continuationPrompt)))