Show More
@@ -0,0 +1,37 b'' | |||||
|
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 = os.popen( global_bin + ' ' + cmdline ).readlines() | |||
|
25 | if simple: | |||
|
26 | parts = [l.split(None,3) for l in lines] | |||
|
27 | lines = ['%s [%s]\n%s' % (p[2].rjust(70),p[1],p[3].rstrip()) for p in parts] | |||
|
28 | print "\n".join(lines) | |||
|
29 | ||||
|
30 | ip.expose_magic('global', global_f) | |||
|
31 | ||||
|
32 | def global_completer(self,event): | |||
|
33 | compl = [l.rstrip() for l in os.popen(global_bin + ' -c ' + event.symbol).readlines()] | |||
|
34 | return compl | |||
|
35 | ||||
|
36 | ip.set_hook('complete_command', global_completer, str_key = '%global') | |||
|
37 |
General Comments 0
You need to be logged in to leave comments.
Login now