~ipython-contrib/+junk/ipython-zmq

« back to all changes in this revision

Viewing changes to IPython/Extensions/ipy_gnuglobal.py

  • Committer: ville
  • Date: 2008-02-16 09:50:47 UTC
  • mto: (0.12.1 ipython_main)
  • mto: This revision was merged to the branch mainline in revision 990.
  • Revision ID: ville@ville-pc-20080216095047-500x6dluki1iz40o
initialization (no svn history)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
 
 
4
"""
 
5
Add %global magic for GNU Global usage.
 
6
 
 
7
http://www.gnu.org/software/global/
 
8
 
 
9
"""
 
10
 
 
11
import IPython.ipapi
 
12
ip = IPython.ipapi.get()
 
13
import os
 
14
 
 
15
# alter to your liking
 
16
global_bin = 'd:/opt/global/bin/global'
 
17
 
 
18
def global_f(self,cmdline):
 
19
    simple = 0
 
20
    if '-' not in cmdline:
 
21
        cmdline  = '-rx ' + cmdline
 
22
        simple = 1
 
23
        
 
24
    lines = [l.rstrip() for l in os.popen( global_bin + ' ' + cmdline ).readlines()]
 
25
    
 
26
    if simple:
 
27
        parts = [l.split(None,3) for l in lines]
 
28
        lines = ['%s [%s]\n%s' % (p[2].rjust(70),p[1],p[3].rstrip()) for p in parts]
 
29
    print "\n".join(lines)
 
30
 
 
31
ip.expose_magic('global', global_f)
 
32
 
 
33
def global_completer(self,event):
 
34
    compl = [l.rstrip() for l in os.popen(global_bin + ' -c ' + event.symbol).readlines()]
 
35
    return compl    
 
36
 
 
37
ip.set_hook('complete_command', global_completer, str_key = '%global')
 
38