Show More
@@ -0,0 +1,77 b'' | |||||
|
1 | """ Shell mode for ipython | |||
|
2 | ||||
|
3 | Start ipython in shell mode by invoking "ipython -p sh" | |||
|
4 | ||||
|
5 | (the old version, "ipython -p pysh" still works but this is the more "modern" | |||
|
6 | shell mode and is recommended for users who don't care about pysh-mode | |||
|
7 | compatibility) | |||
|
8 | ||||
|
9 | ||||
|
10 | """ | |||
|
11 | ||||
|
12 | ||||
|
13 | from IPython import ipapi | |||
|
14 | import os,textwrap | |||
|
15 | ||||
|
16 | def main(): | |||
|
17 | ip = ipapi.get() | |||
|
18 | o = ip.options() | |||
|
19 | # autocall to "full" mode (smart mode is default, I like full mode) | |||
|
20 | ||||
|
21 | o.autocall = 2 | |||
|
22 | ||||
|
23 | # Jason Orendorff's path class is handy to have in user namespace | |||
|
24 | # if you are doing shell-like stuff | |||
|
25 | try: | |||
|
26 | ip.ex("from path import path" ) | |||
|
27 | except ImportError: | |||
|
28 | pass | |||
|
29 | ||||
|
30 | # Get pysh-like prompt for all profiles. | |||
|
31 | ||||
|
32 | o.prompt_in1= '\C_LightBlue[\C_LightCyan\Y1\C_LightBlue]\C_Green|\#> ' | |||
|
33 | o.prompt_in2= '\C_Green|\C_LightGreen\D\C_Green> ' | |||
|
34 | o.prompt_out= '<\#> ' | |||
|
35 | ||||
|
36 | from IPython import Release | |||
|
37 | ||||
|
38 | import sys | |||
|
39 | # I like my banner minimal. | |||
|
40 | o.banner = "Py %s IPy %s\n" % (sys.version.split('\n')[0],Release.version) | |||
|
41 | ||||
|
42 | # make 'd' an alias for ls -F | |||
|
43 | ||||
|
44 | ip.magic('alias d ls -F --color=auto') | |||
|
45 | ||||
|
46 | # Make available all system commands through "rehashing" immediately. | |||
|
47 | # You can comment these lines out to speed up startup on very slow | |||
|
48 | # machines, and to conserve a bit of memory. Note that pysh profile does this | |||
|
49 | # automatically | |||
|
50 | ip.IP.default_option('cd','-q') | |||
|
51 | ||||
|
52 | ||||
|
53 | o.prompts_pad_left="1" | |||
|
54 | # Remove all blank lines in between prompts, like a normal shell. | |||
|
55 | o.separate_in="0" | |||
|
56 | o.separate_out="0" | |||
|
57 | o.separate_out2="0" | |||
|
58 | ||||
|
59 | # now alias all syscommands | |||
|
60 | ||||
|
61 | db = ip.getdb() | |||
|
62 | ||||
|
63 | syscmds = db.get("syscmdlist",[] ) | |||
|
64 | if not syscmds: | |||
|
65 | print textwrap.dedent(""" | |||
|
66 | System command list not initialized, probably the first run... | |||
|
67 | running %rehashx to refresh the command list. Run %rehashx | |||
|
68 | again to refresh command list (after installing new software etc.) | |||
|
69 | """) | |||
|
70 | ip.magic('rehashx') | |||
|
71 | syscmds = db.get("syscmdlist") | |||
|
72 | for cmd in syscmds: | |||
|
73 | #print "al",cmd | |||
|
74 | noext, ext = os.path.splitext(cmd) | |||
|
75 | ip.IP.alias_table[noext] = (0,cmd) | |||
|
76 | ||||
|
77 | main() |
General Comments 0
You need to be logged in to leave comments.
Login now