##// END OF EJS Templates
ipython.rst: cleanup, add sh profile docs, remove deprecated pysh stuff
Ville M. Vainio -
Show More
@@ -228,24 +228,31 b' manner. If you download the tar archive, the process is:'
228 228 ipython with the -upgrade option and it will do this automatically
229 229 for you.
230 230 3. IPython uses distutils, so you can install it by simply typing at
231 the system prompt (don't type the $)
231 the system prompt (don't type the $)::
232
232 233 $ python setup.py install
234
233 235 Note that this assumes you have root access to your machine. If
234 236 you don't have root access or don't want IPython to go in the
235 default python directories, you'll need to use the |--home| option
236 (or |--prefix|). For example:
237 |$ python setup.py install --home $HOME/local|
237 default python directories, you'll need to use the ``--home`` option
238 (or ``--prefix``). For example::
239
240 $ python setup.py install --home $HOME/local
241
238 242 will install IPython into $HOME/local and its subdirectories
239 243 (creating them if necessary).
240 You can type
241 |$ python setup.py --help|
244 You can type::
245
246 $ python setup.py --help
247
242 248 for more details.
243 Note that if you change the default location for |--home| at
249
250 Note that if you change the default location for ``--home`` at
244 251 installation, IPython may end up installed at a location which is
245 252 not part of your $PYTHONPATH environment variable. In this case,
246 253 you'll need to configure this variable to include the actual
247 254 directory where the IPython/ directory ended (typically the value
248 you give to |--home| plus /lib/python).
255 you give to ``--home`` plus /lib/python).
249 256
250 257
251 258 Mac OSX information
@@ -280,10 +287,14 b' and GTK apps. Under OSX, however, this requires that ipython is'
280 287 installed by calling the special pythonw script at installation time,
281 288 which takes care of coordinating things with Apple's graphical environment.
282 289
283 So when installing under OSX, it is best to use the following command:
284 | $ sudo pythonw setup.py install --install-scripts=/usr/local/bin|
290 So when installing under OSX, it is best to use the following command::
291
292 $ sudo pythonw setup.py install --install-scripts=/usr/local/bin
293
285 294 or
286 | $ sudo pythonw setup.py install --install-scripts=/usr/bin|
295
296 $ sudo pythonw setup.py install --install-scripts=/usr/bin
297
287 298 depending on where you like to keep hand-installed executables.
288 299
289 300 The resulting script will have an appropriate shebang line (the first
@@ -294,7 +305,7 b' does not work and has a shebang line that points to, for example, just'
294 305 build/scripts-<python-version> directory. Delete that directory and
295 306 rerun the setup.py.
296 307
297 It is also a good idea to use the special flag |--install-scripts| as
308 It is also a good idea to use the special flag ``--install-scripts`` as
298 309 indicated above, to ensure that the ipython scripts end up in a location
299 310 which is part of your $PATH. Otherwise Apple's Python will put the
300 311 scripts in an internal directory not available by default at the command
@@ -665,11 +676,11 b' the previous section, you may need to set also in your .emacs file::'
665 676 (setq ansi-color-for-comint-mode t)
666 677
667 678
668 Notes::
679 Notes:
669 680
670 681 * There is one caveat you should be aware of: you must start the
671 682 IPython shell before attempting to execute any code regions via
672 C-c |. Simply type C-c ! to start IPython before passing any code
683 ``C-c |``. Simply type C-c ! to start IPython before passing any code
673 684 regions to the interpreter, and you shouldn't experience any
674 685 problems.
675 686 This is due to a bug in Python itself, which has been fixed for
@@ -2824,7 +2835,6 b' Any input line beginning with a ! character is passed verbatim (minus'
2824 2835 the !, of course) to the underlying operating system. For example,
2825 2836 typing !ls will run 'ls' in the current directory.
2826 2837
2827
2828 2838 Manual capture of command output
2829 2839 --------------------------------
2830 2840
@@ -2836,10 +2846,9 b' output. The !! syntax is a shorthand for the %sx magic command.'
2836 2846
2837 2847 Finally, the %sc magic (short for 'shell capture') is similar to %sx,
2838 2848 but allowing more fine-grained control of the capture details, and
2839 storing the result directly into a named variable.
2840
2841 See Sec. 6.2 <#sec:magic> for details on the magics %sc and %sx, or use
2842 IPython's own help (sc? and sx?) for further details.
2849 storing the result directly into a named variable. The direct use of
2850 %sc is now deprecated, and you should ise the ``var = !cmd`` syntax
2851 instead.
2843 2852
2844 2853 IPython also allows you to expand the value of python variables when
2845 2854 making system calls. Any python variable or expression which you prepend
@@ -3008,7 +3017,8 b' Directory history'
3008 3017
3009 3018 Your history of visited directories is kept in the global list _dh, and
3010 3019 the magic %cd command can be used to go to any entry in that list. The
3011 %dhist command allows you to view this history.
3020 %dhist command allows you to view this history. do ``cd -<TAB`` to
3021 conventiently view the directory history.
3012 3022
3013 3023
3014 3024 Automatic parentheses and quotes
@@ -4170,7 +4180,6 b' code fragments in your programs which are ready for cut and paste::'
4170 4180 Using the Python debugger (pdb)
4171 4181 ===============================
4172 4182
4173
4174 4183 Running entire programs via pdb
4175 4184 -------------------------------
4176 4185
@@ -4323,148 +4332,148 b' from math import * # math MUST be imported BEFORE PhysicalQInteractive'
4323 4332 from IPython.Extensions.PhysicalQInteractive import *
4324 4333 import IPython.Extensions.PhysicalQInput
4325 4334
4326 IPython as a system shell
4327 =========================
4328 4335
4329 IPython ships with a special profile called pysh, which you can activate
4330 at the command line as 'ipython -p pysh'. This loads InterpreterExec,
4331 along with some additional facilities and a prompt customized for
4332 filesystem navigation.
4336 IPython as a system shell - the 'Sh' profile
4337 ============================================
4338
4339 The 'sh' profile optimizes IPython for system shell usage. Apart from
4340 certain job control functionality that is present in unix (ctrl+z does
4341 "suspend"), the sh profile should provide you with most of the
4342 functionality you use daily in system shell, and more. Invoke IPython
4343 in 'sh' profile by doing 'ipython -p sh', or (in win32) by launching
4344 the "pysh" shortcut in start menu.
4333 4345
4334 Note that this does not make IPython a full-fledged system shell. In
4335 particular, it has no job control, so if you type Ctrl-Z (under Unix),
4336 you'll suspend pysh itself, not the process you just started.
4346 If you want to use the features of sh profile as your defaults (which
4347 might be a good idea if you use other profiles a lot of the time but
4348 still want the convenience of sh profile), add "import ipy_profile_sh"
4349 to your ~/.ipython/ipy_user_conf.py.
4337 4350
4338 What the shell profile allows you to do is to use the convenient and
4339 powerful syntax of Python to do quick scripting at the command line.
4340 Below we describe some of its features.
4351 The 'sh' profile is different from the default profile in that:
4341 4352
4353 * Prompt shows the current directory
4354 * Spacing between prompts and input is more compact (no padding with
4355 empty lines). The startup banner is more compact as well.
4356 * System commands are directly available (in alias table) without
4357 requesting %rehashx - however, if you install new programs along
4358 your PATH, you might want to run %rehashx to update the persistent
4359 alias table
4360 * Macros are stored in raw format by default. That is, instead of
4361 '_ip.system("cat foo"), the macro will contain text 'cat foo')
4362 * Autocall is in full mode
4363 * Calling "up" does "cd .."
4364
4365 The 'sh' profile is different from the now-obsolete (and unavailable)
4366 'pysh' profile in that:
4367
4368 * '$$var = command' and '$var = command' syntax is not supported
4369 * anymore. Use 'var = !command' instead (incidentally, this is
4370 * available in all IPython profiles). Note that !!command *will*
4371 * work.
4342 4372
4343 4373 Aliases
4344 4374 -------
4345 4375
4346 4376 All of your $PATH has been loaded as IPython aliases, so you should be
4347 able to type any normal system command and have it executed. See %alias?
4348 and %unalias? for details on the alias facilities. See also %rehash? and
4377 able to type any normal system command and have it executed. See
4378 %alias? and %unalias? for details on the alias facilities. See also
4349 4379 %rehashx? for details on the mechanism used to load $PATH.
4350 4380
4351 4381
4352 Special syntax
4353 --------------
4382 Directory management
4383 --------------------
4354 4384
4355 Any lines which begin with '~', '/' and '.' will be executed as shell
4356 commands instead of as Python code. The special escapes below are also
4357 recognized. !cmd is valid in single or multi-line input, all others are
4358 only valid in single-line input::
4385 Since each command passed by ipython to the underlying system is executed
4386 in a subshell which exits immediately, you can NOT use !cd to navigate
4387 the filesystem.
4359 4388
4360 !cmd
4361 pass 'cmd' directly to the shell
4362 !!cmd*
4363 execute 'cmd' and return output as a list (split on '\n')
4364 var=!cmd
4365 capture output of cmd into var, as a string list
4389 IPython provides its own builtin '%cd' magic command to move in the
4390 filesystem (the % is not required with automagic on). It also maintains
4391 a list of visited directories (use %dhist to see it) and allows direct
4392 switching to any of them. Type 'cd?' for more details.
4366 4393
4367 A few brief examples will illustrate these (note that the indentation
4368 below may be incorrectly displayed)::
4394 %pushd, %popd and %dirs are provided for directory stack handling.
4369 4395
4370 fperez[~/test]|3> !ls *s.py
4371 scopes.py strings.py
4372 4396
4373 ls is an internal alias, so there's no need to use !::
4397 Enabled extensions
4398 ------------------
4374 4399
4375 fperez[~/test]|4> ls *s.py
4376 scopes.py* strings.py
4400 Some extensions, listed below, are enabled as default in this profile.
4377 4401
4378 !!ls will return the output into a Python variable FIXME!!!::
4402 envpersist
4403 ++++++++++
4379 4404
4380 fperez[~/test]|5> !!ls *s.py
4381 <5> ['scopes.py', 'strings.py']
4382 fperez[~/test]|6> print _5
4383 ['scopes.py', 'strings.py']
4405 %env can be used to "remember" environment variable manipulations. Examples::
4384 4406
4385 $ and $$ allow direct capture to named variables:
4407 %env - Show all environment variables
4408 %env VISUAL=jed - set VISUAL to jed
4409 %env PATH+=;/foo - append ;foo to PATH
4410 %env PATH+=;/bar - also append ;bar to PATH
4411 %env PATH-=/wbin; - prepend /wbin; to PATH
4412 %env -d VISUAL - forget VISUAL persistent val
4413 %env -p - print all persistent env modifications
4386 4414
4387 fperez[~/test]|7> $astr = ls *s.py
4388 fperez[~/test]|8> astr
4389 <8> 'scopes.py\nstrings.py'
4415 ipy_which
4416 +++++++++
4390 4417
4391 fperez[~/test]|9> $$alist = ls *s.py
4392 fperez[~/test]|10> alist
4393 <10> ['scopes.py', 'strings.py']
4418 %which magic command. Like 'which' in unix, but knows about ipython aliases.
4394 4419
4395 alist is now a normal python list you can loop over. Using $ will expand
4396 back the python values when alias calls are made:
4420 Example::
4397 4421
4398 fperez[~/test]|11> for f in alist:
4399 |..> print 'file',f,
4400 |..> wc -l $f
4401 |..>
4402 file scopes.py 13 scopes.py
4403 file strings.py 4 strings.py
4422 [C:/ipython]|14> %which st
4423 st -> start .
4424 [C:/ipython]|15> %which d
4425 d -> dir /w /og /on
4426 [C:/ipython]|16> %which cp
4427 cp -> cp
4428 == c:\bin\cp.exe
4429 c:\bin\cp.exe
4404 4430
4405 Note that you may need to protect your variables with braces if you want
4406 to append strings to their names. To copy all files in alist to .bak
4407 extensions, you must use::
4431 ipy_app_completers
4432 ++++++++++++++++++
4408 4433
4409 fperez[~/test]|12> for f in alist:
4410 |..> cp $f ${f}.bak
4434 Custom tab completers for some apps like svn, hg, bzr, apt-get. Try 'apt-get install <TAB>' in debian/ubuntu.
4411 4435
4412 If you try using $f.bak, you'll get an AttributeError exception saying
4413 that your string object doesn't have a .bak attribute. This is because
4414 the $ expansion mechanism allows you to expand full Python expressions::
4436 ipy_rehashdir
4437 +++++++++++++
4415 4438
4416 fperez[~/test]|13> echo "sys.platform is: $sys.platform"
4417 sys.platform is: linux2
4439 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::
4418 4440
4419 IPython's input history handling is still active, which allows you to
4420 rerun a single block of multi-line input by simply using exec::
4441 [~]|22> cd c:/opt/PuTTY/
4442 [c:opt/PuTTY]|23> rehashdir .
4443 <23> ['pageant', 'plink', 'pscp', 'psftp', 'putty', 'puttygen', 'unins000']
4421 4444
4422 fperez[~/test]|14> $$alist = ls *.eps
4423 fperez[~/test]|15> exec _i11
4424 file image2.eps 921 image2.eps
4425 file image.eps 921 image.eps
4445 Now, you can execute any of those commams directly::
4426 4446
4427 While these are new special-case syntaxes, they are designed to allow
4428 very efficient use of the shell with minimal typing. At an interactive
4429 shell prompt, conciseness of expression wins over readability.
4447 [c:opt/PuTTY]|24> cd
4448 [~]|25> putty
4430 4449
4450 (the putty window opens).
4431 4451
4432 Useful functions and modules
4433 ----------------------------
4452 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::
4434 4453
4435 The os, sys and shutil modules from the Python standard library are
4436 automatically loaded. Some additional functions, useful for shell usage,
4437 are listed below. You can request more help about them with '?'.
4454 [~]|27> for a in _23:
4455 |..> %store $a
4456 |..>
4457 |..>
4458 Alias stored: pageant (0, 'c:\\opt\\PuTTY\\pageant.exe')
4459 Alias stored: plink (0, 'c:\\opt\\PuTTY\\plink.exe')
4460 Alias stored: pscp (0, 'c:\\opt\\PuTTY\\pscp.exe')
4461 Alias stored: psftp (0, 'c:\\opt\\PuTTY\\psftp.exe')
4462 ...
4438 4463
4439 *shell*
4440 - execute a command in the underlying system shell
4441 *system*
4442 - like shell(), but return the exit status of the command
4443 *sout*
4444 - capture the output of a command as a string
4445 *lout*
4446 - capture the output of a command as a list (split on '\n')
4447 *getoutputerror*
4448 - capture (output,error) of a shell commandss
4464 mglob
4465 +++++
4449 4466
4450 sout/lout are the functional equivalents of $/$$. They are provided to
4451 allow you to capture system output in the middle of true python code,
4452 function definitions, etc (where $ and $$ are invalid).
4467 Provide the magic function %mglob, which makes it easier (than the 'find' command) to collect (possibly recursive) file lists. Examples::
4453 4468
4469 [c:/ipython]|9> mglob *.py
4470 [c:/ipython]|10> mglob *.py rec:*.txt
4471 [c:/ipython]|19> workfiles = %mglob !.svn/ !.hg/ !*_Data/ !*.bak rec:.
4454 4472
4455 Directory management
4456 --------------------
4473 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'.
4457 4474
4458 Since each command passed by pysh to the underlying system is executed
4459 in a subshell which exits immediately, you can NOT use !cd to navigate
4460 the filesystem.
4461 4475
4462 Pysh provides its own builtin '%cd' magic command to move in the
4463 filesystem (the % is not required with automagic on). It also maintains
4464 a list of visited directories (use %dhist to see it) and allows direct
4465 switching to any of them. Type 'cd?' for more details.
4466 4476
4467 %pushd, %popd and %dirs are provided for directory stack handling.
4468 4477
4469 4478
4470 4479 Prompt customization
@@ -4472,80 +4481,64 b' Prompt customization'
4472 4481
4473 4482 The supplied ipy_profile_sh.py profile comes with an example of a very
4474 4483 colored and detailed prompt, mainly to serve as an illustration. The
4475 valid escape sequences, besides color names, are:
4484 valid escape sequences, besides color names, are::
4476 4485
4477 *\#*
4486 \#
4478 4487 - Prompt number, wrapped in the color escapes for the input prompt
4479 4488 (determined by the current color scheme).
4480 *\N*
4489 \N
4481 4490 - Just the prompt counter number, without any coloring wrappers. You
4482 4491 can thus customize the actual prompt colors manually.
4483 *\D*
4492 \D
4484 4493 - Dots, as many as there are digits in \# (so they align).
4485 *\w*
4494 \w
4486 4495 - Current working directory (cwd).
4487 *\W*
4496 \W
4488 4497 - Basename of current working directory.
4489 *\XN*
4498 \XN
4490 4499 - Where N=0..5. N terms of the cwd, with $HOME written as ~.
4491 *\YN*
4500 \YN
4492 4501 - Where N=0..5. Like XN, but if ~ is term N+1 it's also shown.
4493 *\u*
4502 \u
4494 4503 - Username.
4495 *\H*
4504 \H
4496 4505 - Full hostname.
4497 *\h*
4506 \h
4498 4507 - Hostname up to first '.'
4499 *\$*
4508 \$
4500 4509 - Root symbol ($ or #).
4501 *\t*
4510 \t
4502 4511 - Current time, in H:M:S format.
4503 *\v*
4512 \v
4504 4513 - IPython release version.
4505 *\n*
4514 \n
4506 4515 - Newline.
4507 *\r*
4516 \r
4508 4517 - Carriage return.
4509 *\\*
4518 \\
4510 4519 - An explicitly escaped '\'.
4511 4520
4512 4521 You can configure your prompt colors using any ANSI color escape. Each
4513 4522 color escape sets the color for any subsequent text, until another
4514 escape comes in and changes things. The valid color escapes are:
4515
4516 *\C_Black*
4517
4518 *\C_Blue*
4519
4520 *\C_Brown*
4521
4522 *\C_Cyan*
4523
4524 *\C_DarkGray*
4525
4526 *\C_Green*
4527
4528 *\C_LightBlue*
4529
4530 *\C_LightCyan*
4531
4532 *\C_LightGray*
4533
4534 *\C_LightGreen*
4535
4536 *\C_LightPurple*
4537
4538 *\C_LightRed*
4539
4540 *\C_Purple*
4541
4542 *\C_Red*
4543
4544 *\C_White*
4545
4546 *\C_Yellow*
4547
4548 *\C_Normal*
4523 escape comes in and changes things. The valid color escapes are::
4524
4525 \C_Black
4526 \C_Blue
4527 \C_Brown
4528 \C_Cyan
4529 \C_DarkGray
4530 \C_Green
4531 \C_LightBlue
4532 \C_LightCyan
4533 \C_LightGray
4534 \C_LightGreen
4535 \C_LightPurple
4536 \C_LightRed
4537 \C_Purple
4538 \C_Red
4539 \C_White
4540 \C_Yellow
4541 \C_Normal
4549 4542 Stop coloring, defaults to your terminal settings.
4550 4543
4551 4544 Threading support
General Comments 0
You need to be logged in to leave comments. Login now