Show More
@@ -1,90 +1,94 b'' | |||
|
1 | 1 | """ Tab completion support for a couple of linux package managers |
|
2 | 2 | |
|
3 | 3 | This is also an example of how to write custom completer plugins |
|
4 | 4 | or hooks. |
|
5 | 5 | |
|
6 | 6 | Practical use: |
|
7 | 7 | |
|
8 | 8 | [ipython]|1> import ipy_linux_package_managers |
|
9 | 9 | [ipython]|2> apt-get u<<< press tab here >>> |
|
10 | 10 | update upgrade |
|
11 | 11 | [ipython]|2> apt-get up |
|
12 | 12 | |
|
13 | 13 | """ |
|
14 | 14 | import IPython.ipapi |
|
15 | 15 | |
|
16 | 16 | ip = IPython.ipapi.get() |
|
17 | 17 | |
|
18 | 18 | def apt_completers(self, event): |
|
19 | 19 | """ This should return a list of strings with possible completions. |
|
20 | 20 | |
|
21 | 21 | Note that all the included strings that don't start with event.symbol |
|
22 | 22 | are removed, in order to not confuse readline. |
|
23 | 23 | |
|
24 | 24 | """ |
|
25 | 25 | # print event # dbg |
|
26 | 26 | |
|
27 | 27 | # commands are only suggested for the 'command' part of package manager |
|
28 | 28 | # invocation |
|
29 | 29 | |
|
30 | 30 | cmd = (event.line + "<placeholder>").rsplit(None,1)[0] |
|
31 | 31 | # print cmd |
|
32 | 32 | if cmd.endswith('apt-get') or cmd.endswith('yum'): |
|
33 | 33 | return ['update', 'upgrade', 'install', 'remove'] |
|
34 | 34 | |
|
35 | 35 | # later on, add dpkg -l / whatever to get list of possible |
|
36 | 36 | # packages, add switches etc. for the rest of command line |
|
37 | 37 | # filling |
|
38 | 38 | |
|
39 | 39 | raise IPython.ipapi.TryNext |
|
40 | 40 | |
|
41 | 41 | |
|
42 | 42 | # re_key specifies the regexp that triggers the specified completer |
|
43 | 43 | |
|
44 | 44 | ip.set_hook('complete_command', apt_completers, re_key = '.*apt-get') |
|
45 | 45 | ip.set_hook('complete_command', apt_completers, re_key = '.*yum') |
|
46 | 46 | |
|
47 | 47 | py_std_modules = """\ |
|
48 | 48 | BaseHTTPServer Bastion CGIHTTPServer ConfigParser Cookie |
|
49 | 49 | DocXMLRPCServer HTMLParser MimeWriter Queue SimpleHTTPServer |
|
50 | 50 | SimpleXMLRPCServer SocketServer StringIO UserDict UserList UserString |
|
51 | 51 | _LWPCookieJar _MozillaCookieJar __future__ __phello__.foo _strptime |
|
52 | 52 | _threading_local aifc anydbm asynchat asyncore atexit audiodev base64 |
|
53 | 53 | bdb binhex bisect cProfile calendar cgi cgitb chunk cmd code codecs |
|
54 | 54 | codeop colorsys commands compileall contextlib cookielib copy copy_reg |
|
55 | 55 | csv dbhash decimal difflib dircache dis doctest dumbdbm dummy_thread |
|
56 | 56 | dummy_threading filecmp fileinput fnmatch formatter fpformat ftplib |
|
57 | 57 | functools getopt getpass gettext glob gopherlib gzip hashlib heapq |
|
58 | 58 | hmac htmlentitydefs htmllib httplib ihooks imaplib imghdr imputil |
|
59 | 59 | inspect keyword linecache locale macpath macurl2path mailbox mailcap |
|
60 | 60 | markupbase md5 mhlib mimetools mimetypes mimify modulefinder multifile |
|
61 | 61 | mutex netrc new nntplib ntpath nturl2path opcode optparse os |
|
62 | 62 | os2emxpath pdb pickle pickletools pipes pkgutil platform popen2 poplib |
|
63 | 63 | posixfile posixpath pprint profile pstats pty py_compile pyclbr pydoc |
|
64 | 64 | quopri random re repr rexec rfc822 rlcompleter robotparser runpy sched |
|
65 | 65 | sets sgmllib sha shelve shlex shutil site smtpd smtplib sndhdr socket |
|
66 | 66 | sre sre_compile sre_constants sre_parse stat statvfs string stringold |
|
67 | 67 | stringprep struct subprocess sunau sunaudio symbol symtable tabnanny |
|
68 | 68 | tarfile telnetlib tempfile textwrap this threading timeit toaiff token |
|
69 | 69 | tokenize trace traceback tty types unittest urllib urllib2 urlparse |
|
70 | 70 | user uu uuid warnings wave weakref webbrowser whichdb xdrlib xmllib |
|
71 | 71 | xmlrpclib zipfile""" |
|
72 | 72 | |
|
73 | 73 | def module_completer(self,event): |
|
74 | 74 | """ Give completions after user has typed 'import' """ |
|
75 | 75 | return py_std_modules.split() |
|
76 | 76 | |
|
77 | 77 | ip.set_hook('complete_command', module_completer, str_key = 'import') |
|
78 | 78 | |
|
79 | 79 | svn_commands = """\ |
|
80 | 80 | add blame praise annotate ann cat checkout co cleanup commit ci copy |
|
81 | 81 | cp delete del remove rm diff di export help ? h import info list ls |
|
82 | 82 | lock log merge mkdir move mv rename ren propdel pdel pd propedit pedit |
|
83 | 83 | pe propget pget pg proplist plist pl propset pset ps resolved revert |
|
84 | status stat st switch sw unlock | |
|
84 | status stat st switch sw unlock update | |
|
85 | 85 | """ |
|
86 | 86 | |
|
87 | def svn_completer(self,even): | |
|
87 | def svn_completer(self,event): | |
|
88 | if len((event.line + 'placeholder').split()) > 2: | |
|
89 | # the rest are probably file names | |
|
90 | return ip.IP.Completer.file_matches(event.symbol) | |
|
91 | ||
|
88 | 92 | return svn_commands.split() |
|
89 | 93 | |
|
90 | 94 | ip.set_hook('complete_command', svn_completer, str_key = 'svn') No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now