Show More
@@ -1,272 +1,273 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | """Modified input prompt for executing files. |
|
2 | """Modified input prompt for executing files. | |
3 |
|
3 | |||
4 | We define a special input line filter to allow typing lines which begin with |
|
4 | We define a special input line filter to allow typing lines which begin with | |
5 | '~', '/' or '.'. If one of those strings is encountered, it is automatically |
|
5 | '~', '/' or '.'. If one of those strings is encountered, it is automatically | |
6 | executed. |
|
6 | executed. | |
7 |
|
7 | |||
8 |
$Id: InterpreterExec.py 9 |
|
8 | $Id: InterpreterExec.py 1039 2006-01-20 23:59:33Z vivainio $""" | |
9 |
|
9 | |||
10 | #***************************************************************************** |
|
10 | #***************************************************************************** | |
11 | # Copyright (C) 2004 W.J. van der Laan <gnufnork@hetdigitalegat.nl> |
|
11 | # Copyright (C) 2004 W.J. van der Laan <gnufnork@hetdigitalegat.nl> | |
12 | # Copyright (C) 2004-2006 Fernando Perez <fperez@colorado.edu> |
|
12 | # Copyright (C) 2004-2006 Fernando Perez <fperez@colorado.edu> | |
13 | # |
|
13 | # | |
14 | # Distributed under the terms of the BSD License. The full license is in |
|
14 | # Distributed under the terms of the BSD License. The full license is in | |
15 | # the file COPYING, distributed as part of this software. |
|
15 | # the file COPYING, distributed as part of this software. | |
16 | #***************************************************************************** |
|
16 | #***************************************************************************** | |
17 |
|
17 | |||
18 | from IPython import Release |
|
18 | from IPython import Release | |
19 | __author__ = 'W.J. van der Laan <gnufnork@hetdigitalegat.nl>, '\ |
|
19 | __author__ = 'W.J. van der Laan <gnufnork@hetdigitalegat.nl>, '\ | |
20 | '%s <%s>' % Release.authors['Fernando'] |
|
20 | '%s <%s>' % Release.authors['Fernando'] | |
21 | __license__ = Release.license |
|
21 | __license__ = Release.license | |
22 |
|
22 | |||
23 | def prefilter_shell(self,line,continuation): |
|
23 | def prefilter_shell(self,line,continuation): | |
24 | """Alternate prefilter, modified for shell-like functionality. |
|
24 | """Alternate prefilter, modified for shell-like functionality. | |
25 |
|
25 | |||
26 | - Execute all lines beginning with '~', '/' or '.' |
|
26 | - Execute all lines beginning with '~', '/' or '.' | |
27 | - $var=cmd <=> %sc var=cmd |
|
27 | - $var=cmd <=> %sc var=cmd | |
28 | - $$var=cmd <=> %sc -l var=cmd |
|
28 | - $$var=cmd <=> %sc -l var=cmd | |
29 | """ |
|
29 | """ | |
30 |
|
30 | |||
31 | if line: |
|
31 | if line: | |
32 | l0 = line[0] |
|
32 | l0 = line[0] | |
33 | if l0 in '~/.': |
|
33 | if l0 in '~/.': | |
34 | return self._prefilter("!%s"%line,continuation) |
|
34 | return self._prefilter("!%s"%line,continuation) | |
35 | elif l0=='$': |
|
35 | elif l0=='$': | |
36 | lrest = line[1:] |
|
36 | lrest = line[1:] | |
37 | if lrest.startswith('$'): |
|
37 | if lrest.startswith('$'): | |
38 | # $$var=cmd <=> %sc -l var=cmd |
|
38 | # $$var=cmd <=> %sc -l var=cmd | |
39 | return self._prefilter("%ssc -l %s" % (self.ESC_MAGIC,lrest[1:]), |
|
39 | return self._prefilter("%ssc -l %s" % (self.ESC_MAGIC,lrest[1:]), | |
40 | continuation) |
|
40 | continuation) | |
41 | else: |
|
41 | else: | |
42 | # $var=cmd <=> %sc var=cmd |
|
42 | # $var=cmd <=> %sc var=cmd | |
43 | return self._prefilter("%ssc %s" % (self.ESC_MAGIC,lrest), |
|
43 | return self._prefilter("%ssc %s" % (self.ESC_MAGIC,lrest), | |
44 | continuation) |
|
44 | continuation) | |
45 | else: |
|
45 | else: | |
46 | return self._prefilter(line,continuation) |
|
46 | return self._prefilter(line,continuation) | |
47 | else: |
|
47 | else: | |
48 | return self._prefilter(line,continuation) |
|
48 | return self._prefilter(line,continuation) | |
49 |
|
49 | |||
50 | # Rebind this to be the new IPython prefilter: |
|
50 | # Rebind this to be the new IPython prefilter: | |
51 | from IPython.iplib import InteractiveShell |
|
51 | from IPython.iplib import InteractiveShell | |
52 | InteractiveShell.prefilter = prefilter_shell |
|
52 | InteractiveShell.prefilter = prefilter_shell | |
53 | # Clean up the namespace. |
|
53 | # Clean up the namespace. | |
54 | del InteractiveShell,prefilter_shell |
|
54 | del InteractiveShell,prefilter_shell | |
55 |
|
55 | |||
56 | # Provide pysh and further shell-oriented services |
|
56 | # Provide pysh and further shell-oriented services | |
57 | import os,sys,shutil |
|
57 | import os,sys,shutil | |
58 | from IPython.genutils import system,shell,getoutput,getoutputerror |
|
58 | from IPython.genutils import system,shell,getoutput,getoutputerror | |
59 |
|
59 | |||
60 | # Short aliases for getting shell output as a string and a list |
|
60 | # Short aliases for getting shell output as a string and a list | |
61 | sout = getoutput |
|
61 | sout = getoutput | |
62 | lout = lambda cmd: getoutput(cmd,split=1) |
|
62 | lout = lambda cmd: getoutput(cmd,split=1) | |
63 |
|
63 | |||
64 | # Empty function, meant as a docstring holder so help(pysh) works. |
|
64 | # Empty function, meant as a docstring holder so help(pysh) works. | |
65 | def pysh(): |
|
65 | def pysh(): | |
66 | """Pysh is a set of modules and extensions to IPython which make shell-like |
|
66 | """Pysh is a set of modules and extensions to IPython which make shell-like | |
67 | usage with Python syntax more convenient. Keep in mind that pysh is NOT a |
|
67 | usage with Python syntax more convenient. Keep in mind that pysh is NOT a | |
68 | full-blown shell, so don't try to make it your /etc/passwd entry! |
|
68 | full-blown shell, so don't try to make it your /etc/passwd entry! | |
69 |
|
69 | |||
70 | In particular, it has no job control, so if you type Ctrl-Z (under Unix), |
|
70 | In particular, it has no job control, so if you type Ctrl-Z (under Unix), | |
71 | you'll suspend pysh itself, not the process you just started. |
|
71 | you'll suspend pysh itself, not the process you just started. | |
72 |
|
72 | |||
73 | Since pysh is really nothing but a customized IPython, you should |
|
73 | Since pysh is really nothing but a customized IPython, you should | |
74 | familiarize yourself with IPython's features. This brief help mainly |
|
74 | familiarize yourself with IPython's features. This brief help mainly | |
75 | documents areas in which pysh differs from the normal IPython. |
|
75 | documents areas in which pysh differs from the normal IPython. | |
76 |
|
76 | |||
77 | ALIASES |
|
77 | ALIASES | |
78 | ------- |
|
78 | ------- | |
79 | All of your $PATH has been loaded as IPython aliases, so you should be |
|
79 | All of your $PATH has been loaded as IPython aliases, so you should be | |
80 | able to type any normal system command and have it executed. See %alias? |
|
80 | able to type any normal system command and have it executed. See %alias? | |
81 | and %unalias? for details on the alias facilities. |
|
81 | and %unalias? for details on the alias facilities. | |
82 |
|
82 | |||
83 | SPECIAL SYNTAX |
|
83 | SPECIAL SYNTAX | |
84 | -------------- |
|
84 | -------------- | |
85 | Any lines which begin with '~', '/' and '.' will be executed as shell |
|
85 | Any lines which begin with '~', '/' and '.' will be executed as shell | |
86 | commands instead of as Python code. The special escapes below are also |
|
86 | commands instead of as Python code. The special escapes below are also | |
87 | recognized. !cmd is valid in single or multi-line input, all others are |
|
87 | recognized. !cmd is valid in single or multi-line input, all others are | |
88 | only valid in single-line input: |
|
88 | only valid in single-line input: | |
89 |
|
89 | |||
90 | !cmd - pass 'cmd' directly to the shell |
|
90 | !cmd - pass 'cmd' directly to the shell | |
91 | !!cmd - execute 'cmd' and return output as a list (split on '\\n') |
|
91 | !!cmd - execute 'cmd' and return output as a list (split on '\\n') | |
92 | $var=cmd - capture output of cmd into var, as a string |
|
92 | $var=cmd - capture output of cmd into var, as a string | |
93 | $$var=cmd - capture output of cmd into var, as a list (split on '\\n') |
|
93 | $$var=cmd - capture output of cmd into var, as a list (split on '\\n') | |
94 |
|
94 | |||
95 | The $/$$ syntaxes make Python variables from system output, which you can |
|
95 | The $/$$ syntaxes make Python variables from system output, which you can | |
96 | later use for further scripting. The converse is also possible: when |
|
96 | later use for further scripting. The converse is also possible: when | |
97 | executing an alias or calling to the system via !/!!, you can expand any |
|
97 | executing an alias or calling to the system via !/!!, you can expand any | |
98 | python variable or expression by prepending it with $. Full details of |
|
98 | python variable or expression by prepending it with $. Full details of | |
99 | the allowed syntax can be found in Python's PEP 215. |
|
99 | the allowed syntax can be found in Python's PEP 215. | |
100 |
|
100 | |||
101 | A few brief examples will illustrate these: |
|
101 | A few brief examples will illustrate these: | |
102 |
|
102 | |||
103 | fperez[~/test]|3> !ls *s.py |
|
103 | fperez[~/test]|3> !ls *s.py | |
104 | scopes.py strings.py |
|
104 | scopes.py strings.py | |
105 |
|
105 | |||
106 | ls is an internal alias, so there's no need to use !: |
|
106 | ls is an internal alias, so there's no need to use !: | |
107 | fperez[~/test]|4> ls *s.py |
|
107 | fperez[~/test]|4> ls *s.py | |
108 | scopes.py* strings.py |
|
108 | scopes.py* strings.py | |
109 |
|
109 | |||
110 | !!ls will return the output into a Python variable: |
|
110 | !!ls will return the output into a Python variable: | |
111 | fperez[~/test]|5> !!ls *s.py |
|
111 | fperez[~/test]|5> !!ls *s.py | |
112 | <5> ['scopes.py', 'strings.py'] |
|
112 | <5> ['scopes.py', 'strings.py'] | |
113 | fperez[~/test]|6> print _5 |
|
113 | fperez[~/test]|6> print _5 | |
114 | ['scopes.py', 'strings.py'] |
|
114 | ['scopes.py', 'strings.py'] | |
115 |
|
115 | |||
116 | $ and $$ allow direct capture to named variables: |
|
116 | $ and $$ allow direct capture to named variables: | |
117 | fperez[~/test]|7> $astr = ls *s.py |
|
117 | fperez[~/test]|7> $astr = ls *s.py | |
118 | fperez[~/test]|8> astr |
|
118 | fperez[~/test]|8> astr | |
119 | <8> 'scopes.py\\nstrings.py' |
|
119 | <8> 'scopes.py\\nstrings.py' | |
120 |
|
120 | |||
121 | fperez[~/test]|9> $$alist = ls *s.py |
|
121 | fperez[~/test]|9> $$alist = ls *s.py | |
122 | fperez[~/test]|10> alist |
|
122 | fperez[~/test]|10> alist | |
123 | <10> ['scopes.py', 'strings.py'] |
|
123 | <10> ['scopes.py', 'strings.py'] | |
124 |
|
124 | |||
125 | alist is now a normal python list you can loop over. Using $ will expand |
|
125 | alist is now a normal python list you can loop over. Using $ will expand | |
126 | back the python values when alias calls are made: |
|
126 | back the python values when alias calls are made: | |
127 | fperez[~/test]|11> for f in alist: |
|
127 | fperez[~/test]|11> for f in alist: | |
128 | |..> print 'file',f, |
|
128 | |..> print 'file',f, | |
129 | |..> wc -l $f |
|
129 | |..> wc -l $f | |
130 | |..> |
|
130 | |..> | |
131 | file scopes.py 13 scopes.py |
|
131 | file scopes.py 13 scopes.py | |
132 | file strings.py 4 strings.py |
|
132 | file strings.py 4 strings.py | |
133 |
|
133 | |||
134 | Note that you may need to protect your variables with braces if you want |
|
134 | Note that you may need to protect your variables with braces if you want | |
135 | to append strings to their names. To copy all files in alist to .bak |
|
135 | to append strings to their names. To copy all files in alist to .bak | |
136 | extensions, you must use: |
|
136 | extensions, you must use: | |
137 | fperez[~/test]|12> for f in alist: |
|
137 | fperez[~/test]|12> for f in alist: | |
138 | |..> cp $f ${f}.bak |
|
138 | |..> cp $f ${f}.bak | |
139 |
|
139 | |||
140 | If you try using $f.bak, you'll get an AttributeError exception saying |
|
140 | If you try using $f.bak, you'll get an AttributeError exception saying | |
141 | that your string object doesn't have a .bak attribute. This is because |
|
141 | that your string object doesn't have a .bak attribute. This is because | |
142 | the $ expansion mechanism allows you to expand full Python expressions: |
|
142 | the $ expansion mechanism allows you to expand full Python expressions: | |
143 | fperez[~/test]|13> echo "sys.platform is: $sys.platform" |
|
143 | fperez[~/test]|13> echo "sys.platform is: $sys.platform" | |
144 | sys.platform is: linux2 |
|
144 | sys.platform is: linux2 | |
145 |
|
145 | |||
146 | IPython's input history handling is still active, which allows you to |
|
146 | IPython's input history handling is still active, which allows you to | |
147 | rerun a single block of multi-line input by simply using exec: |
|
147 | rerun a single block of multi-line input by simply using exec: | |
148 | fperez[~/test]|14> $$alist = ls *.eps |
|
148 | fperez[~/test]|14> $$alist = ls *.eps | |
149 | fperez[~/test]|15> exec _i11 |
|
149 | fperez[~/test]|15> exec _i11 | |
150 | file image2.eps 921 image2.eps |
|
150 | file image2.eps 921 image2.eps | |
151 | file image.eps 921 image.eps |
|
151 | file image.eps 921 image.eps | |
152 |
|
152 | |||
153 | While these are new special-case syntaxes, they are designed to allow very |
|
153 | While these are new special-case syntaxes, they are designed to allow very | |
154 | efficient use of the shell with minimal typing. At an interactive shell |
|
154 | efficient use of the shell with minimal typing. At an interactive shell | |
155 | prompt, conciseness of expression wins over readability. |
|
155 | prompt, conciseness of expression wins over readability. | |
156 |
|
156 | |||
157 | USEFUL FUNCTIONS AND MODULES |
|
157 | USEFUL FUNCTIONS AND MODULES | |
158 | ---------------------------- |
|
158 | ---------------------------- | |
159 | The os, sys and shutil modules from the Python standard library are |
|
159 | The os, sys and shutil modules from the Python standard library are | |
160 | automatically loaded. Some additional functions, useful for shell usage, |
|
160 | automatically loaded. Some additional functions, useful for shell usage, | |
161 | are listed below. You can request more help about them with '?'. |
|
161 | are listed below. You can request more help about them with '?'. | |
162 |
|
162 | |||
163 | shell - execute a command in the underlying system shell |
|
163 | shell - execute a command in the underlying system shell | |
164 | system - like shell(), but return the exit status of the command |
|
164 | system - like shell(), but return the exit status of the command | |
165 | sout - capture the output of a command as a string |
|
165 | sout - capture the output of a command as a string | |
166 | lout - capture the output of a command as a list (split on '\\n') |
|
166 | lout - capture the output of a command as a list (split on '\\n') | |
167 | getoutputerror - capture (output,error) of a shell command |
|
167 | getoutputerror - capture (output,error) of a shell command | |
168 |
|
168 | |||
169 | sout/lout are the functional equivalents of $/$$. They are provided to |
|
169 | sout/lout are the functional equivalents of $/$$. They are provided to | |
170 | allow you to capture system output in the middle of true python code, |
|
170 | allow you to capture system output in the middle of true python code, | |
171 | function definitions, etc (where $ and $$ are invalid). |
|
171 | function definitions, etc (where $ and $$ are invalid). | |
172 |
|
172 | |||
173 | DIRECTORY MANAGEMENT |
|
173 | DIRECTORY MANAGEMENT | |
174 | -------------------- |
|
174 | -------------------- | |
175 | Since each command passed by pysh to the underlying system is executed in |
|
175 | Since each command passed by pysh to the underlying system is executed in | |
176 | a subshell which exits immediately, you can NOT use !cd to navigate the |
|
176 | a subshell which exits immediately, you can NOT use !cd to navigate the | |
177 | filesystem. |
|
177 | filesystem. | |
178 |
|
178 | |||
179 | Pysh provides its own builtin '%cd' magic command to move in the |
|
179 | Pysh provides its own builtin '%cd' magic command to move in the | |
180 | filesystem (the % is not required with automagic on). It also maintains a |
|
180 | filesystem (the % is not required with automagic on). It also maintains a | |
181 | list of visited directories (use %dhist to see it) and allows direct |
|
181 | list of visited directories (use %dhist to see it) and allows direct | |
182 | switching to any of them. Type 'cd?' for more details. |
|
182 | switching to any of them. Type 'cd?' for more details. | |
183 |
|
183 | |||
184 | %pushd, %popd and %dirs are provided for directory stack handling. |
|
184 | %pushd, %popd and %dirs are provided for directory stack handling. | |
185 |
|
185 | |||
186 | PROMPT CUSTOMIZATION |
|
186 | PROMPT CUSTOMIZATION | |
187 | -------------------- |
|
187 | -------------------- | |
188 |
|
188 | |||
189 | The supplied ipythonrc-pysh profile comes with an example of a very |
|
189 | The supplied ipythonrc-pysh profile comes with an example of a very | |
190 | colored and detailed prompt, mainly to serve as an illustration. The |
|
190 | colored and detailed prompt, mainly to serve as an illustration. The | |
191 | valid escape sequences, besides color names, are: |
|
191 | valid escape sequences, besides color names, are: | |
192 |
|
192 | |||
193 | \\# - Prompt number. |
|
193 | \\# - Prompt number. | |
194 | \\D - Dots, as many as there are digits in \\# (so they align). |
|
194 | \\D - Dots, as many as there are digits in \\# (so they align). | |
195 | \\w - Current working directory (cwd). |
|
195 | \\w - Current working directory (cwd). | |
196 | \\W - Basename of current working directory. |
|
196 | \\W - Basename of current working directory. | |
197 | \\XN - Where N=0..5. N terms of the cwd, with $HOME written as ~. |
|
197 | \\XN - Where N=0..5. N terms of the cwd, with $HOME written as ~. | |
198 | \\YN - Where N=0..5. Like XN, but if ~ is term N+1 it's also shown. |
|
198 | \\YN - Where N=0..5. Like XN, but if ~ is term N+1 it's also shown. | |
199 | \\u - Username. |
|
199 | \\u - Username. | |
200 | \\H - Full hostname. |
|
200 | \\H - Full hostname. | |
201 | \\h - Hostname up to first '.' |
|
201 | \\h - Hostname up to first '.' | |
202 | \\$ - Root symbol ($ or #). |
|
202 | \\$ - Root symbol ($ or #). | |
203 | \\t - Current time, in H:M:S format. |
|
203 | \\t - Current time, in H:M:S format. | |
204 | \\v - IPython release version. |
|
204 | \\v - IPython release version. | |
205 | \\n - Newline. |
|
205 | \\n - Newline. | |
206 | \\r - Carriage return. |
|
206 | \\r - Carriage return. | |
207 | \\\\ - An explicitly escaped '\\'. |
|
207 | \\\\ - An explicitly escaped '\\'. | |
208 |
|
208 | |||
209 | You can configure your prompt colors using any ANSI color escape. Each |
|
209 | You can configure your prompt colors using any ANSI color escape. Each | |
210 | color escape sets the color for any subsequent text, until another escape |
|
210 | color escape sets the color for any subsequent text, until another escape | |
211 | comes in and changes things. The valid color escapes are: |
|
211 | comes in and changes things. The valid color escapes are: | |
212 |
|
212 | |||
213 | \\C_Black |
|
213 | \\C_Black | |
214 | \\C_Blue |
|
214 | \\C_Blue | |
215 | \\C_Brown |
|
215 | \\C_Brown | |
216 | \\C_Cyan |
|
216 | \\C_Cyan | |
217 | \\C_DarkGray |
|
217 | \\C_DarkGray | |
218 | \\C_Green |
|
218 | \\C_Green | |
219 | \\C_LightBlue |
|
219 | \\C_LightBlue | |
220 | \\C_LightCyan |
|
220 | \\C_LightCyan | |
221 | \\C_LightGray |
|
221 | \\C_LightGray | |
222 | \\C_LightGreen |
|
222 | \\C_LightGreen | |
223 | \\C_LightPurple |
|
223 | \\C_LightPurple | |
224 | \\C_LightRed |
|
224 | \\C_LightRed | |
225 | \\C_Purple |
|
225 | \\C_Purple | |
226 | \\C_Red |
|
226 | \\C_Red | |
227 | \\C_White |
|
227 | \\C_White | |
228 | \\C_Yellow |
|
228 | \\C_Yellow | |
229 | \\C_Normal - Stop coloring, defaults to your terminal settings. |
|
229 | \\C_Normal - Stop coloring, defaults to your terminal settings. | |
230 | """ |
|
230 | """ | |
231 | pass |
|
231 | pass | |
232 |
|
232 | |||
233 | # Configure a few things. Much of this is fairly hackish, since IPython |
|
233 | # Configure a few things. Much of this is fairly hackish, since IPython | |
234 | # doesn't really expose a clean API for it. Be careful if you start making |
|
234 | # doesn't really expose a clean API for it. Be careful if you start making | |
235 | # many modifications here. |
|
235 | # many modifications here. | |
236 |
|
236 | |||
237 | print """\ |
|
237 | print """\ | |
238 | Welcome to pysh, a set of extensions to IPython for shell usage. |
|
238 | Welcome to pysh, a set of extensions to IPython for shell usage. | |
239 | help(pysh) -> help on the installed shell extensions and syntax. |
|
239 | help(pysh) -> help on the installed shell extensions and syntax. | |
240 | """ |
|
240 | """ | |
241 |
|
241 | |||
242 | # Set the 'cd' command to quiet mode, a more shell-like behavior |
|
242 | # Set the 'cd' command to quiet mode, a more shell-like behavior | |
243 | __IPYTHON__.default_option('cd','-q') |
|
243 | __IPYTHON__.default_option('cd','-q') | |
244 |
|
244 | |||
|
245 | # This is redundant, ipy_user_conf.py will determine this | |||
245 | # Load all of $PATH as aliases |
|
246 | # Load all of $PATH as aliases | |
246 | if os.name == 'posix': |
|
247 | #if os.name == 'posix': | |
247 | # %rehash is very fast, but it doesn't check for executability, it simply |
|
248 | # # %rehash is very fast, but it doesn't check for executability, it simply | |
248 | # dumps everything in $PATH as an alias. Use rehashx if you want more |
|
249 | # # dumps everything in $PATH as an alias. Use rehashx if you want more | |
249 | # checks. |
|
250 | # # checks. | |
250 | __IPYTHON__.magic_rehash() |
|
251 | # __IPYTHON__.magic_rehash() | |
251 | else: |
|
252 | #else: | |
252 | # Windows users: the list of extensions considered executable is read from |
|
253 | # # Windows users: the list of extensions considered executable is read from | |
253 | # the environment variable 'pathext'. If this is undefined, IPython |
|
254 | # # the environment variable 'pathext'. If this is undefined, IPython | |
254 | # defaults to EXE, COM and BAT. |
|
255 | # # defaults to EXE, COM and BAT. | |
255 | # %rehashx is the one which does extension analysis, at the cost of |
|
256 | # # %rehashx is the one which does extension analysis, at the cost of | |
256 | # being much slower than %rehash. |
|
257 | # # being much slower than %rehash. | |
257 | __IPYTHON__.magic_rehashx() |
|
258 | # __IPYTHON__.magic_rehashx() | |
258 |
|
259 | |||
259 | # Remove %sc,%sx if present as aliases |
|
260 | # Remove %sc,%sx if present as aliases | |
260 | __IPYTHON__.magic_unalias('sc') |
|
261 | __IPYTHON__.magic_unalias('sc') | |
261 | __IPYTHON__.magic_unalias('sx') |
|
262 | __IPYTHON__.magic_unalias('sx') | |
262 |
|
263 | |||
263 | # We need different criteria for line-splitting, so that aliases such as |
|
264 | # We need different criteria for line-splitting, so that aliases such as | |
264 | # 'gnome-terminal' are interpreted as a single alias instead of variable |
|
265 | # 'gnome-terminal' are interpreted as a single alias instead of variable | |
265 | # 'gnome' minus variable 'terminal'. |
|
266 | # 'gnome' minus variable 'terminal'. | |
266 | import re |
|
267 | import re | |
267 | __IPYTHON__.line_split = re.compile(r'^([\s*,;/])' |
|
268 | __IPYTHON__.line_split = re.compile(r'^([\s*,;/])' | |
268 | r'([\?\w\.\-\+]+\w*\s*)' |
|
269 | r'([\?\w\.\-\+]+\w*\s*)' | |
269 | r'(\(?.*$)') |
|
270 | r'(\(?.*$)') | |
270 |
|
271 | |||
271 | # Namespace cleanup |
|
272 | # Namespace cleanup | |
272 | del re |
|
273 | del re |
@@ -1,43 +1,49 b'' | |||||
1 | """ User configuration file for IPython |
|
1 | """ User configuration file for IPython | |
2 |
|
2 | |||
3 | This is a more flexible and safe way to configure ipython than *rc files |
|
3 | This is a more flexible and safe way to configure ipython than *rc files | |
4 | (ipythonrc, ipythonrc-pysh etc.) |
|
4 | (ipythonrc, ipythonrc-pysh etc.) | |
5 |
|
5 | |||
6 | This file is always imported on ipython startup. You should import all the |
|
6 | This file is always imported on ipython startup. You should import all the | |
7 | ipython extensions you need here (see IPython/Extensions directory). |
|
7 | ipython extensions you need here (see IPython/Extensions directory). | |
8 |
|
8 | |||
9 | Feel free to edit this file to customize your ipython experience. If |
|
9 | Feel free to edit this file to customize your ipython experience. If | |
10 | you wish to only use the old config system, it's perfectly ok to make this file |
|
10 | you wish to only use the old config system, it's perfectly ok to make this file | |
11 | empty. |
|
11 | empty. | |
12 |
|
12 | |||
13 | """ |
|
13 | """ | |
14 |
|
14 | |||
15 | # Most of your config files and extensions will probably start with this import |
|
15 | # Most of your config files and extensions will probably start with this import | |
16 |
|
16 | |||
17 | import IPython.ipapi as ip |
|
17 | import IPython.ipapi as ip | |
18 |
|
18 | |||
|
19 | import os | |||
19 |
|
20 | |||
20 | o = ip.options() |
|
21 | o = ip.options() | |
21 | # autocall 1 ('smart') is default anyway, this is just an |
|
22 | # autocall 1 ('smart') is default anyway, this is just an | |
22 | # example on how to set an option |
|
23 | # example on how to set an option | |
23 | o.autocall = 1 |
|
24 | o.autocall = 1 | |
24 |
|
25 | |||
25 | if o.profile == 'pysh': |
|
26 | if o.profile == 'pysh': | |
26 | # Jason Orendorff's path class is handy to have in user namespace |
|
27 | # Jason Orendorff's path class is handy to have in user namespace | |
27 | # if you are doing shell-like stuff |
|
28 | # if you are doing shell-like stuff | |
28 | ip.ex("from IPython.path import path" ) |
|
29 | ip.ex("from IPython.path import path" ) | |
29 |
|
30 | |||
30 | # Uncomment these lines to get pysh-like prompt for all profiles. |
|
31 | # Uncomment these lines to get pysh-like prompt for all profiles. | |
31 |
|
32 | |||
32 | #o.prompt_in1= '\C_LightBlue[\C_LightCyan\Y1\C_LightBlue]\C_Green|\#> ' |
|
33 | #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_in2= '\C_Green|\C_LightGreen\D\C_Green> ' | |
34 | #o.prompt_out= '<\#> ' |
|
35 | #o.prompt_out= '<\#> ' | |
35 |
|
36 | |||
36 | # make 'd' an alias for ls -F |
|
37 | # make 'd' an alias for ls -F | |
37 |
|
38 | |||
38 | ip.magic('alias d ls -F --color=auto') |
|
39 | ip.magic('alias d ls -F --color=auto') | |
39 |
|
40 | |||
40 |
# Make available all system commands |
|
41 | # Make available all system commands through "rehashing" immediately. | |
41 | # startup on slow machines, and to conserve a bit of memory |
|
42 | # You can comment these lines out to speed up startup on very slow | |
|
43 | # machines, and to conserve a bit of memory. | |||
42 |
|
44 | |||
43 | ip.magic('rehashx') No newline at end of file |
|
45 | if os.name=='posix': | |
|
46 | ip.magic('rehash') | |||
|
47 | else: | |||
|
48 | #slightly slower, but better results esp. with Windows | |||
|
49 | ip.magic('rehashx') |
General Comments 0
You need to be logged in to leave comments.
Login now