File: ipy_gnuglobal.py

package info (click to toggle)
ipython 0.13.1-2%2Bdeb7u1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 15,752 kB
  • sloc: python: 69,537; makefile: 355; lisp: 272; sh: 80; objc: 37
file content (35 lines) | stat: -rw-r--r-- 867 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""
Add %global magic for GNU Global usage.

http://www.gnu.org/software/global/

"""

from IPython.core import ipapi
ip = ipapi.get()
import os

# alter to your liking
global_bin = 'd:/opt/global/bin/global'

def global_f(self,cmdline):
    simple = 0
    if '-' not in cmdline:
        cmdline  = '-rx ' + cmdline
        simple = 1
        
    lines = [l.rstrip() for l in os.popen( global_bin + ' ' + cmdline ).readlines()]
    
    if simple:
        parts = [l.split(None,3) for l in lines]
        lines = ['%s [%s]\n%s' % (p[2].rjust(70),p[1],p[3].rstrip()) for p in parts]
    print "\n".join(lines)

ip.define_magic('global', global_f)

def global_completer(self,event):
    compl = [l.rstrip() for l in os.popen(global_bin + ' -c ' + event.symbol).readlines()]
    return compl    

ip.set_hook('complete_command', global_completer, str_key = '%global')