##// END OF EJS Templates
restore interactive/shell doc with warning...
MinRK -
Show More
@@ -1,14 +1,14 b''
1 1 ==================================
2 2 Using IPython for interactive work
3 3 ==================================
4 4
5 5 .. toctree::
6 6 :maxdepth: 2
7 7
8 8 tutorial.txt
9 9 tips.txt
10 10 reference.txt
11 .. shell.txt
11 shell.txt
12 12 qtconsole.txt
13 13
14 14
@@ -1,293 +1,294 b''
1 1 .. _ipython_as_shell:
2 2
3 3 =========================
4 4 IPython as a system shell
5 5 =========================
6 6
7 7 .. warning::
8 8
9 As of the 0.11 version of IPython, some of the features and APIs
10 described in this section have been deprecated or are broken. Our plan
11 is to continue to support these features, but they need to be updated
12 to take advantage of recent API changes. Furthermore, this section
13 of the documentation need to be updated to reflect all of these changes.
9 As of the 0.11 version of IPython, most of the APIs used by the shell
10 profile have been changed, so the profile currently does very little
11 beyond changing the IPython prompt. To help restore the shell
12 profile to past functionality described here, the old code is found in
13 :file:`IPython/deathrow`, which needs to be updated to use the
14 APIs in 0.11.
14 15
15 16 Overview
16 17 ========
17 18
18 19 The 'sh' profile optimizes IPython for system shell usage. Apart from
19 20 certain job control functionality that is present in unix (ctrl+z does
20 21 "suspend"), the sh profile should provide you with most of the
21 22 functionality you use daily in system shell, and more. Invoke IPython
22 23 in 'sh' profile by doing 'ipython -p sh', or (in win32) by launching
23 24 the "pysh" shortcut in start menu.
24 25
25 26 If you want to use the features of sh profile as your defaults (which
26 27 might be a good idea if you use other profiles a lot of the time but
27 28 still want the convenience of sh profile), add ``import ipy_profile_sh``
28 29 to your $IPYTHON_DIR/ipy_user_conf.py.
29 30
30 31 The 'sh' profile is different from the default profile in that:
31 32
32 33 * Prompt shows the current directory
33 34 * Spacing between prompts and input is more compact (no padding with
34 35 empty lines). The startup banner is more compact as well.
35 36 * System commands are directly available (in alias table) without
36 37 requesting %rehashx - however, if you install new programs along
37 38 your PATH, you might want to run %rehashx to update the persistent
38 39 alias table
39 40 * Macros are stored in raw format by default. That is, instead of
40 41 '_ip.system("cat foo"), the macro will contain text 'cat foo')
41 42 * Autocall is in full mode
42 43 * Calling "up" does "cd .."
43 44
44 45 The 'sh' profile is different from the now-obsolete (and unavailable)
45 46 'pysh' profile in that:
46 47
47 48 * '$$var = command' and '$var = command' syntax is not supported
48 49 * anymore. Use 'var = !command' instead (incidentally, this is
49 50 * available in all IPython profiles). Note that !!command *will*
50 51 * work.
51 52
52 53 Aliases
53 54 =======
54 55
55 56 All of your $PATH has been loaded as IPython aliases, so you should be
56 57 able to type any normal system command and have it executed. See
57 58 %alias? and %unalias? for details on the alias facilities. See also
58 59 %rehashx? for details on the mechanism used to load $PATH.
59 60
60 61
61 62 Directory management
62 63 ====================
63 64
64 65 Since each command passed by ipython to the underlying system is executed
65 66 in a subshell which exits immediately, you can NOT use !cd to navigate
66 67 the filesystem.
67 68
68 69 IPython provides its own builtin '%cd' magic command to move in the
69 70 filesystem (the % is not required with automagic on). It also maintains
70 71 a list of visited directories (use %dhist to see it) and allows direct
71 72 switching to any of them. Type 'cd?' for more details.
72 73
73 74 %pushd, %popd and %dirs are provided for directory stack handling.
74 75
75 76
76 77 Enabled extensions
77 78 ==================
78 79
79 80 Some extensions, listed below, are enabled as default in this profile.
80 81
81 82 envpersist
82 83 ----------
83 84
84 85 %env can be used to "remember" environment variable manipulations. Examples::
85 86
86 87 %env - Show all environment variables
87 88 %env VISUAL=jed - set VISUAL to jed
88 89 %env PATH+=;/foo - append ;foo to PATH
89 90 %env PATH+=;/bar - also append ;bar to PATH
90 91 %env PATH-=/wbin; - prepend /wbin; to PATH
91 92 %env -d VISUAL - forget VISUAL persistent val
92 93 %env -p - print all persistent env modifications
93 94
94 95 ipy_which
95 96 ---------
96 97
97 98 %which magic command. Like 'which' in unix, but knows about ipython aliases.
98 99
99 100 Example::
100 101
101 102 [C:/ipython]|14> %which st
102 103 st -> start .
103 104 [C:/ipython]|15> %which d
104 105 d -> dir /w /og /on
105 106 [C:/ipython]|16> %which cp
106 107 cp -> cp
107 108 == c:\bin\cp.exe
108 109 c:\bin\cp.exe
109 110
110 111 ipy_app_completers
111 112 ------------------
112 113
113 114 Custom tab completers for some apps like svn, hg, bzr, apt-get. Try 'apt-get install <TAB>' in debian/ubuntu.
114 115
115 116 ipy_rehashdir
116 117 -------------
117 118
118 119 Allows you to add system command aliases for commands that are not along your path. Let's say that you just installed Putty and want to be able to invoke it without adding it to path, you can create the alias for it with rehashdir::
119 120
120 121 [~]|22> cd c:/opt/PuTTY/
121 122 [c:opt/PuTTY]|23> rehashdir .
122 123 <23> ['pageant', 'plink', 'pscp', 'psftp', 'putty', 'puttygen', 'unins000']
123 124
124 125 Now, you can execute any of those commams directly::
125 126
126 127 [c:opt/PuTTY]|24> cd
127 128 [~]|25> putty
128 129
129 130 (the putty window opens).
130 131
131 132 If you want to store the alias so that it will always be available, do '%store putty'. If you want to %store all these aliases persistently, just do it in a for loop::
132 133
133 134 [~]|27> for a in _23:
134 135 |..> %store $a
135 136 |..>
136 137 |..>
137 138 Alias stored: pageant (0, 'c:\\opt\\PuTTY\\pageant.exe')
138 139 Alias stored: plink (0, 'c:\\opt\\PuTTY\\plink.exe')
139 140 Alias stored: pscp (0, 'c:\\opt\\PuTTY\\pscp.exe')
140 141 Alias stored: psftp (0, 'c:\\opt\\PuTTY\\psftp.exe')
141 142 ...
142 143
143 144 mglob
144 145 -----
145 146
146 147 Provide the magic function %mglob, which makes it easier (than the 'find' command) to collect (possibly recursive) file lists. Examples::
147 148
148 149 [c:/ipython]|9> mglob *.py
149 150 [c:/ipython]|10> mglob *.py rec:*.txt
150 151 [c:/ipython]|19> workfiles = %mglob !.svn/ !.hg/ !*_Data/ !*.bak rec:.
151 152
152 153 Note that the first 2 calls will put the file list in result history (_, _9, _10), and the last one will assign it to 'workfiles'.
153 154
154 155
155 156 Prompt customization
156 157 ====================
157 158
158 159 The sh profile uses the following prompt configurations::
159 160
160 161 o.prompt_in1= r'\C_LightBlue[\C_LightCyan\Y2\C_LightBlue]\C_Green|\#>'
161 162 o.prompt_in2= r'\C_Green|\C_LightGreen\D\C_Green>'
162 163
163 164 You can change the prompt configuration to your liking by editing
164 165 ipy_user_conf.py.
165 166
166 167 String lists
167 168 ============
168 169
169 170 String lists (IPython.utils.text.SList) are handy way to process output
170 171 from system commands. They are produced by ``var = !cmd`` syntax.
171 172
172 173 First, we acquire the output of 'ls -l'::
173 174
174 175 [Q:doc/examples]|2> lines = !ls -l
175 176 ==
176 177 ['total 23',
177 178 '-rw-rw-rw- 1 ville None 1163 Sep 30 2006 example-demo.py',
178 179 '-rw-rw-rw- 1 ville None 1927 Sep 30 2006 example-embed-short.py',
179 180 '-rwxrwxrwx 1 ville None 4606 Sep 1 17:15 example-embed.py',
180 181 '-rwxrwxrwx 1 ville None 1017 Sep 30 2006 example-gnuplot.py',
181 182 '-rwxrwxrwx 1 ville None 339 Jun 11 18:01 extension.py',
182 183 '-rwxrwxrwx 1 ville None 113 Dec 20 2006 seteditor.py',
183 184 '-rwxrwxrwx 1 ville None 245 Dec 12 2006 seteditor.pyc']
184 185
185 186 Now, let's take a look at the contents of 'lines' (the first number is
186 187 the list element number)::
187 188
188 189 [Q:doc/examples]|3> lines
189 190 <3> SList (.p, .n, .l, .s, .grep(), .fields() available). Value:
190 191
191 192 0: total 23
192 193 1: -rw-rw-rw- 1 ville None 1163 Sep 30 2006 example-demo.py
193 194 2: -rw-rw-rw- 1 ville None 1927 Sep 30 2006 example-embed-short.py
194 195 3: -rwxrwxrwx 1 ville None 4606 Sep 1 17:15 example-embed.py
195 196 4: -rwxrwxrwx 1 ville None 1017 Sep 30 2006 example-gnuplot.py
196 197 5: -rwxrwxrwx 1 ville None 339 Jun 11 18:01 extension.py
197 198 6: -rwxrwxrwx 1 ville None 113 Dec 20 2006 seteditor.py
198 199 7: -rwxrwxrwx 1 ville None 245 Dec 12 2006 seteditor.pyc
199 200
200 201 Now, let's filter out the 'embed' lines::
201 202
202 203 [Q:doc/examples]|4> l2 = lines.grep('embed',prune=1)
203 204 [Q:doc/examples]|5> l2
204 205 <5> SList (.p, .n, .l, .s, .grep(), .fields() available). Value:
205 206
206 207 0: total 23
207 208 1: -rw-rw-rw- 1 ville None 1163 Sep 30 2006 example-demo.py
208 209 2: -rwxrwxrwx 1 ville None 1017 Sep 30 2006 example-gnuplot.py
209 210 3: -rwxrwxrwx 1 ville None 339 Jun 11 18:01 extension.py
210 211 4: -rwxrwxrwx 1 ville None 113 Dec 20 2006 seteditor.py
211 212 5: -rwxrwxrwx 1 ville None 245 Dec 12 2006 seteditor.pyc
212 213
213 214 Now, we want strings having just file names and permissions::
214 215
215 216 [Q:doc/examples]|6> l2.fields(8,0)
216 217 <6> SList (.p, .n, .l, .s, .grep(), .fields() available). Value:
217 218
218 219 0: total
219 220 1: example-demo.py -rw-rw-rw-
220 221 2: example-gnuplot.py -rwxrwxrwx
221 222 3: extension.py -rwxrwxrwx
222 223 4: seteditor.py -rwxrwxrwx
223 224 5: seteditor.pyc -rwxrwxrwx
224 225
225 226 Note how the line with 'total' does not raise IndexError.
226 227
227 228 If you want to split these (yielding lists), call fields() without
228 229 arguments::
229 230
230 231 [Q:doc/examples]|7> _.fields()
231 232 <7>
232 233 [['total'],
233 234 ['example-demo.py', '-rw-rw-rw-'],
234 235 ['example-gnuplot.py', '-rwxrwxrwx'],
235 236 ['extension.py', '-rwxrwxrwx'],
236 237 ['seteditor.py', '-rwxrwxrwx'],
237 238 ['seteditor.pyc', '-rwxrwxrwx']]
238 239
239 240 If you want to pass these separated with spaces to a command (typical
240 241 for lists if files), use the .s property::
241 242
242 243
243 244 [Q:doc/examples]|13> files = l2.fields(8).s
244 245 [Q:doc/examples]|14> files
245 246 <14> 'example-demo.py example-gnuplot.py extension.py seteditor.py seteditor.pyc'
246 247 [Q:doc/examples]|15> ls $files
247 248 example-demo.py example-gnuplot.py extension.py seteditor.py seteditor.pyc
248 249
249 250 SLists are inherited from normal python lists, so every list method is
250 251 available::
251 252
252 253 [Q:doc/examples]|21> lines.append('hey')
253 254
254 255
255 256 Real world example: remove all files outside version control
256 257 ============================================================
257 258
258 259 First, capture output of "hg status"::
259 260
260 261 [Q:/ipython]|28> out = !hg status
261 262 ==
262 263 ['M IPython\\extensions\\ipy_kitcfg.py',
263 264 'M IPython\\extensions\\ipy_rehashdir.py',
264 265 ...
265 266 '? build\\lib\\IPython\\Debugger.py',
266 267 '? build\\lib\\IPython\\extensions\\InterpreterExec.py',
267 268 '? build\\lib\\IPython\\extensions\\InterpreterPasteInput.py',
268 269 ...
269 270
270 271 (lines starting with ? are not under version control).
271 272
272 273 ::
273 274
274 275 [Q:/ipython]|35> junk = out.grep(r'^\?').fields(1)
275 276 [Q:/ipython]|36> junk
276 277 <36> SList (.p, .n, .l, .s, .grep(), .fields() availab
277 278 ...
278 279 10: build\bdist.win32\winexe\temp\_ctypes.py
279 280 11: build\bdist.win32\winexe\temp\_hashlib.py
280 281 12: build\bdist.win32\winexe\temp\_socket.py
281 282
282 283 Now we can just remove these files by doing 'rm $junk.s'.
283 284
284 285 The .s, .n, .p properties
285 286 =========================
286 287
287 288 The '.s' property returns one string where lines are separated by
288 289 single space (for convenient passing to system commands). The '.n'
289 290 property return one string where the lines are separated by '\n'
290 291 (i.e. the original output of the function). If the items in string
291 292 list are file names, '.p' can be used to get a list of "path" objects
292 293 for convenient file manipulation.
293 294
@@ -1,127 +1,131 b''
1 1 #!python
2 2 """Windows-specific part of the installation"""
3 3
4 4 import os, sys, shutil
5 5 pjoin = os.path.join
6 6
7 7 # import setuptools if we can
8 8 try:
9 9 import setuptools
10 10 except ImportError:
11 11 pass
12 12
13 13 def mkshortcut(target,description,link_file,*args,**kw):
14 14 """make a shortcut if it doesn't exist, and register its creation"""
15 15
16 16 create_shortcut(target, description, link_file,*args,**kw)
17 17 file_created(link_file)
18 18
19 19 def install():
20 20 """Routine to be run by the win32 installer with the -install switch."""
21 21
22 22 from IPython.core.release import version
23 23
24 24 # Get some system constants
25 25 prefix = sys.prefix
26 26 python = pjoin(prefix, 'python.exe')
27 27 pythonw = pjoin(prefix, 'pythonw.exe')
28 28 have_setuptools = 'setuptools' in sys.modules
29 29
30 30 if not have_setuptools:
31 31 # This currently doesn't work without setuptools,
32 32 # so don't bother making broken links
33 33 return
34 34
35 35 # Lookup path to common startmenu ...
36 36 ip_start_menu = pjoin(get_special_folder_path('CSIDL_COMMON_PROGRAMS'), 'IPython')
37 37 # Create IPython entry ...
38 38 if not os.path.isdir(ip_start_menu):
39 39 os.mkdir(ip_start_menu)
40 40 directory_created(ip_start_menu)
41 41
42 42 # Create .py and .bat files to make things available from
43 43 # the Windows command line. Thanks to the Twisted project
44 44 # for this logic!
45 45 programs = [
46 46 'ipython',
47 47 'iptest',
48 48 'ipcontroller',
49 49 'ipengine',
50 50 'ipcluster',
51 51 'irunner'
52 52 ]
53 53 scripts = pjoin(prefix,'scripts')
54 54 if not have_setuptools:
55 55 # only create .bat files if we don't have setuptools
56 56 for program in programs:
57 57 raw = pjoin(scripts, program)
58 58 bat = raw + '.bat'
59 59 py = raw + '.py'
60 60 # Create .py versions of the scripts
61 61 shutil.copy(raw, py)
62 62 # Create .bat files for each of the scripts
63 63 bat_file = file(bat,'w')
64 64 bat_file.write("@%s %s %%*" % (python, py))
65 65 bat_file.close()
66 66
67 67 # Now move onto setting the Start Menu up
68 68 ipybase = pjoin(scripts, 'ipython')
69 69 if have_setuptools:
70 70 # let setuptools take care of the scripts:
71 71 ipybase = ipybase + '-script.py'
72 72 workdir = "%HOMEDRIVE%%HOMEPATH%"
73 73
74 74 link = pjoin(ip_start_menu, 'IPython.lnk')
75 75 cmd = '"%s"' % ipybase
76 76 mkshortcut(python, 'IPython', link, cmd, workdir)
77 77
78 link = pjoin(ip_start_menu, 'pysh.lnk')
79 cmd = '"%s" profile=pysh --init' % ipybase
80 mkshortcut(python, 'IPython (command prompt mode)', link, cmd, workdir)
78 # Disable pysh Start item until the profile restores functionality
79 # Most of this code is in IPython/deathrow, and needs to be updated
80 # to 0.11 APIs
81
82 # link = pjoin(ip_start_menu, 'pysh.lnk')
83 # cmd = '"%s" profile=pysh --init' % ipybase
84 # mkshortcut(python, 'IPython (command prompt mode)', link, cmd, workdir)
81 85
82 86 link = pjoin(ip_start_menu, 'pylab.lnk')
83 87 cmd = '"%s" profile=pylab --init' % ipybase
84 88 mkshortcut(python, 'IPython (pylab profile)', link, cmd, workdir)
85 89
86 90 link = pjoin(ip_start_menu, 'ipcontroller.lnk')
87 91 cmdbase = pjoin(scripts, 'ipcontroller')
88 92 if have_setuptools:
89 93 cmdbase += '-script.py'
90 94 cmd = '"%s"' % cmdbase
91 95 mkshortcut(python, 'IPython controller', link, cmd, workdir)
92 96
93 97 link = pjoin(ip_start_menu, 'ipengine.lnk')
94 98 cmdbase = pjoin(scripts, 'ipengine')
95 99 if have_setuptools:
96 100 cmdbase += '-script.py'
97 101 cmd = '"%s"' % cmdbase
98 102 mkshortcut(python, 'IPython engine', link, cmd, workdir)
99 103
100 104 link = pjoin(ip_start_menu, 'ipythonqt.lnk')
101 105 cmdbase = pjoin(scripts, 'ipython-qtconsole')
102 106 if have_setuptools:
103 107 cmdbase += '-script.pyw'
104 108 cmd = '"%s"' % cmdbase
105 109 mkshortcut(pythonw, 'IPython Qt Console', link, cmd, workdir)
106 110 # Create documentation shortcuts ...
107 111 t = prefix + r'\share\doc\ipython\manual\ipython.pdf'
108 112 f = ip_start_menu + r'\Manual in PDF.lnk'
109 113 mkshortcut(t,r'IPython Manual - PDF-Format',f)
110 114
111 115 t = prefix + r'\share\doc\ipython\manual\html\index.html'
112 116 f = ip_start_menu + r'\Manual in HTML.lnk'
113 117 mkshortcut(t,'IPython Manual - HTML-Format',f)
114 118
115 119
116 120 def remove():
117 121 """Routine to be run by the win32 installer with the -remove switch."""
118 122 pass
119 123
120 124 # main()
121 125 if len(sys.argv) > 1:
122 126 if sys.argv[1] == '-install':
123 127 install()
124 128 elif sys.argv[1] == '-remove':
125 129 remove()
126 130 else:
127 131 print "Script was called with option %s" % sys.argv[1]
General Comments 0
You need to be logged in to leave comments. Login now