##// END OF EJS Templates
Merge pull request #13668 from telamonian/fix-handling-of-bdbquit...
Merge pull request #13668 from telamonian/fix-handling-of-bdbquit fix uncaught `BdbQuit` exceptions on ipdb `exit`

File last commit:

r26422:fac67105
r27659:1893a8f5 merge
Show More
shell.rst
214 lines | 7.4 KiB | text/x-rst | RstLexer
Brian E Granger
Massive reorganization of the IPython documentation. It is now ready to be hacked on by users. ...
r1258 .. _ipython_as_shell:
Matthias Bussonnier
Inform user they shoudl use Xonsh instead of system shell
r26422 .. note::
This page has been kept for historical reason. You most likely want to use
`Xonsh <https://xon.sh/>`__ instead of this.
Brian E Granger
Massive reorganization of the IPython documentation. It is now ready to be hacked on by users. ...
r1258 =========================
IPython as a system shell
=========================
MinRK
add extra clear warning to shell doc...
r7709
Brian Granger
Work on documentation....
r2276
Brian E Granger
Massive reorganization of the IPython documentation. It is now ready to be hacked on by users. ...
r1258 Overview
========
Paul Ivanov
added more references to shell
r11608 It is possible to adapt IPython for system shell usage. In the past, IPython
shipped a special 'sh' profile for this purpose, but it had been quarantined
since 0.11 release, and in 1.0 it was removed altogether. Nevertheless, much
of this section relies on machinery which does not require a custom profile.
Paul Ivanov
updating shell mode - lots has been removed...
r11607
Paul Ivanov
added more references to shell
r11608 You can set up your own 'sh' :ref:`profile <Profiles>` to be different from
the default profile such that:
Paul Ivanov
updating shell mode - lots has been removed...
r11607
* Prompt shows the current directory (see `Prompt customization`_)
Paul Ivanov
added more references to shell
r11608 * Make system commands directly available (in alias table) by running the
``%rehashx`` magic. If you install new programs along your PATH, you might
want to run ``%rehashx`` to update the alias table
Paul Ivanov
updating shell mode - lots has been removed...
r11607 * turn ``%autocall`` to full mode
Brian E Granger
Massive reorganization of the IPython documentation. It is now ready to be hacked on by users. ...
r1258
Paul Ivanov
added more references to shell
r11608
mvr
[pr6953-docs] update docstrings/whatsnew/shell.rst for env/set_env magic
r19335 Environment variables
=====================
Rather than manipulating os.environ directly, you may like to use the magic
`%env` command. With no arguments, this displays all environment variables
and values. To get the value of a specific variable, use `%env var`. To set
the value of a specific variable, use `%env foo bar`, `%env foo=bar`. By
default values are considered to be strings so quoting them is unnecessary.
Joe Borg
Capitalising Python...
r21565 However, Python variables are expanded as usual in the magic command, so
mvr
[pr6953-docs] update docstrings/whatsnew/shell.rst for env/set_env magic
r19335 `%env foo=$bar` means "set the environment variable foo to the value of the
Joe Borg
Capitalising Python...
r21565 Python variable `bar`".
mvr
[pr6953-docs] update docstrings/whatsnew/shell.rst for env/set_env magic
r19335
Brian E Granger
Massive reorganization of the IPython documentation. It is now ready to be hacked on by users. ...
r1258 Aliases
=======
Paul Ivanov
updating shell mode - lots has been removed...
r11607 Once you run ``%rehashx``, all of your $PATH has been loaded as IPython aliases,
so you should be able to type any normal system command and have it executed.
See ``%alias?`` and ``%unalias?`` for details on the alias facilities. See also
``%rehashx?`` for details on the mechanism used to load $PATH.
Brian E Granger
Massive reorganization of the IPython documentation. It is now ready to be hacked on by users. ...
r1258
Matthias Bussonnier
Inform user they shoudl use Xonsh instead of system shell
r26422 .. warning::
See info at the top of the page. You most likely want to use
`Xonsh <https://xon.sh/>`__ instead of this.
Brian E Granger
Massive reorganization of the IPython documentation. It is now ready to be hacked on by users. ...
r1258
Directory management
====================
Joe Borg
Capitalising Python...
r21565 Since each command passed by IPython to the underlying system is executed
Brian E Granger
Massive reorganization of the IPython documentation. It is now ready to be hacked on by users. ...
r1258 in a subshell which exits immediately, you can NOT use !cd to navigate
the filesystem.
Paul Ivanov
updating shell mode - lots has been removed...
r11607 IPython provides its own builtin ``%cd`` magic command to move in the
Brian E Granger
Massive reorganization of the IPython documentation. It is now ready to be hacked on by users. ...
r1258 filesystem (the % is not required with automagic on). It also maintains
Paul Ivanov
updating shell mode - lots has been removed...
r11607 a list of visited directories (use ``%dhist`` to see it) and allows direct
switching to any of them. Type ``cd?`` for more details.
Brian E Granger
Massive reorganization of the IPython documentation. It is now ready to be hacked on by users. ...
r1258
Paul Ivanov
updating shell mode - lots has been removed...
r11607 ``%pushd``, ``%popd`` and ``%dirs`` are provided for directory stack handling.
Brian E Granger
Massive reorganization of the IPython documentation. It is now ready to be hacked on by users. ...
r1258
Prompt customization
====================
Thomas Kluyver
Unify docs on custom prompts...
r22690 See :ref:`custom_prompts`.
Matthias Bussonnier
Add some documentation on how to configure prompts.
r22430
Paul Ivanov
added more references to shell
r11608
Thomas Kluyver
Tidy up docs for shell profile.
r5443 .. _string_lists:
Brian E Granger
Massive reorganization of the IPython documentation. It is now ready to be hacked on by users. ...
r1258
String lists
============
Brian Granger
Work to address the review comments on Fernando's branch....
r2498 String lists (IPython.utils.text.SList) are handy way to process output
Brian E Granger
Massive reorganization of the IPython documentation. It is now ready to be hacked on by users. ...
r1258 from system commands. They are produced by ``var = !cmd`` syntax.
First, we acquire the output of 'ls -l'::
[Q:doc/examples]|2> lines = !ls -l
==
['total 23',
'-rw-rw-rw- 1 ville None 1163 Sep 30 2006 example-demo.py',
'-rw-rw-rw- 1 ville None 1927 Sep 30 2006 example-embed-short.py',
'-rwxrwxrwx 1 ville None 4606 Sep 1 17:15 example-embed.py',
'-rwxrwxrwx 1 ville None 1017 Sep 30 2006 example-gnuplot.py',
'-rwxrwxrwx 1 ville None 339 Jun 11 18:01 extension.py',
'-rwxrwxrwx 1 ville None 113 Dec 20 2006 seteditor.py',
'-rwxrwxrwx 1 ville None 245 Dec 12 2006 seteditor.pyc']
Now, let's take a look at the contents of 'lines' (the first number is
the list element number)::
[Q:doc/examples]|3> lines
<3> SList (.p, .n, .l, .s, .grep(), .fields() available). Value:
0: total 23
1: -rw-rw-rw- 1 ville None 1163 Sep 30 2006 example-demo.py
2: -rw-rw-rw- 1 ville None 1927 Sep 30 2006 example-embed-short.py
3: -rwxrwxrwx 1 ville None 4606 Sep 1 17:15 example-embed.py
4: -rwxrwxrwx 1 ville None 1017 Sep 30 2006 example-gnuplot.py
5: -rwxrwxrwx 1 ville None 339 Jun 11 18:01 extension.py
6: -rwxrwxrwx 1 ville None 113 Dec 20 2006 seteditor.py
7: -rwxrwxrwx 1 ville None 245 Dec 12 2006 seteditor.pyc
Now, let's filter out the 'embed' lines::
[Q:doc/examples]|4> l2 = lines.grep('embed',prune=1)
[Q:doc/examples]|5> l2
<5> SList (.p, .n, .l, .s, .grep(), .fields() available). Value:
0: total 23
1: -rw-rw-rw- 1 ville None 1163 Sep 30 2006 example-demo.py
2: -rwxrwxrwx 1 ville None 1017 Sep 30 2006 example-gnuplot.py
3: -rwxrwxrwx 1 ville None 339 Jun 11 18:01 extension.py
4: -rwxrwxrwx 1 ville None 113 Dec 20 2006 seteditor.py
5: -rwxrwxrwx 1 ville None 245 Dec 12 2006 seteditor.pyc
Now, we want strings having just file names and permissions::
[Q:doc/examples]|6> l2.fields(8,0)
<6> SList (.p, .n, .l, .s, .grep(), .fields() available). Value:
0: total
1: example-demo.py -rw-rw-rw-
2: example-gnuplot.py -rwxrwxrwx
3: extension.py -rwxrwxrwx
4: seteditor.py -rwxrwxrwx
5: seteditor.pyc -rwxrwxrwx
Note how the line with 'total' does not raise IndexError.
If you want to split these (yielding lists), call fields() without
arguments::
[Q:doc/examples]|7> _.fields()
<7>
[['total'],
['example-demo.py', '-rw-rw-rw-'],
['example-gnuplot.py', '-rwxrwxrwx'],
['extension.py', '-rwxrwxrwx'],
['seteditor.py', '-rwxrwxrwx'],
['seteditor.pyc', '-rwxrwxrwx']]
If you want to pass these separated with spaces to a command (typical
for lists if files), use the .s property::
[Q:doc/examples]|13> files = l2.fields(8).s
[Q:doc/examples]|14> files
<14> 'example-demo.py example-gnuplot.py extension.py seteditor.py seteditor.pyc'
[Q:doc/examples]|15> ls $files
example-demo.py example-gnuplot.py extension.py seteditor.py seteditor.pyc
Joe Borg
Capitalising Python...
r21565 SLists are inherited from normal Python lists, so every list method is
Brian E Granger
Massive reorganization of the IPython documentation. It is now ready to be hacked on by users. ...
r1258 available::
[Q:doc/examples]|21> lines.append('hey')
Real world example: remove all files outside version control
Thomas Kluyver
Tidy up docs for shell profile.
r5443 ------------------------------------------------------------
Brian E Granger
Massive reorganization of the IPython documentation. It is now ready to be hacked on by users. ...
r1258
First, capture output of "hg status"::
[Q:/ipython]|28> out = !hg status
==
Brian Granger
Renaming Extensions=>extensions in code and imports.
r2064 ['M IPython\\extensions\\ipy_kitcfg.py',
'M IPython\\extensions\\ipy_rehashdir.py',
Brian E Granger
Massive reorganization of the IPython documentation. It is now ready to be hacked on by users. ...
r1258 ...
'? build\\lib\\IPython\\Debugger.py',
Brian Granger
Renaming Extensions=>extensions in code and imports.
r2064 '? build\\lib\\IPython\\extensions\\InterpreterExec.py',
'? build\\lib\\IPython\\extensions\\InterpreterPasteInput.py',
Brian E Granger
Massive reorganization of the IPython documentation. It is now ready to be hacked on by users. ...
r1258 ...
(lines starting with ? are not under version control).
::
[Q:/ipython]|35> junk = out.grep(r'^\?').fields(1)
[Q:/ipython]|36> junk
<36> SList (.p, .n, .l, .s, .grep(), .fields() availab
...
10: build\bdist.win32\winexe\temp\_ctypes.py
11: build\bdist.win32\winexe\temp\_hashlib.py
12: build\bdist.win32\winexe\temp\_socket.py
klonuo
Fix code/code-block errors
r22474 Now we can just remove these files by doing 'rm $junk.s'.
Brian E Granger
Massive reorganization of the IPython documentation. It is now ready to be hacked on by users. ...
r1258
anatoly techtonik
More readable .n, .s, .p reference
r24907 The .n, .s, .p properties
Thomas Kluyver
Tidy up docs for shell profile.
r5443 -------------------------
Brian E Granger
Massive reorganization of the IPython documentation. It is now ready to be hacked on by users. ...
r1258
anatoly techtonik
Add link to SList API
r24911 Properties of `SList <https://ipython.readthedocs.io/en/stable/api/generated/IPython.utils.text.html?highlight=SList#IPython.utils.text.SList>`_ wrapper
provide a convenient ways to use contained text in different formats:
anatoly techtonik
Add summary to SList properties explanation
r24908
anatoly techtonik
More readable .n, .s, .p reference
r24907 * ``.n`` returns (original) string with lines separated by a newline
* ``.s`` returns string with lines separated by single space (for
convenient passing to system commands)
anatoly techtonik
Reword ``.p`` explanation
r24909 * ``.p`` returns list of "path" objects from detected file names
Matthias Bussonnier
Inform user they shoudl use Xonsh instead of system shell
r26422
.. error::
You went too far scroll back up. You most likely want to use
`Xonsh <https://xon.sh/>`__ instead of this.