GitXplorerGitXplorer
t

bash_kernel

public
710 stars
142 forks
13 issues

Commits

List of commits on branch master.
Verified
629d3f6ec66eb35b8d765634f7d7f4f90e3939e5

replace deprecated stdlib imghdr with filetype

jjans-code committed a month ago
Verified
e6f0b066b1b99048a44b89968306b61fed1629b6

Update README

kkdm9 committed 8 months ago
Verified
1433fd56e899a497f6085c9d433478bb5b5da3e3

Add note on #142 to README.rst

kkdm9 committed 8 months ago
Verified
5c2eaaba15ba787693e87d8c380a6d2ebe9b2bd1

Add pipx instructions to README

kkdm9 committed 8 months ago
Unverified
4ec510ab8a32e0bb71f4ba55db201349e47e4ace

version bump

kkdm9 committed a year ago
Verified
55b6597ef6982a2a7894649b16a92ac56f921a8a

fixes #123, bash xtrace now works correctly (#136)

aabbbe committed a year ago

README

The README file for this repository.

.. image:: https://mybinder.org/badge_logo.svg :target: https://mybinder.org/v2/gh/takluyver/bash_kernel/master

========================= A Jupyter kernel for bash

Installation

This requires IPython 3.

.. code:: shell

pip install bash_kernel
python -m bash_kernel.install

To use it, run one of:

.. code:: shell

jupyter notebook
# In the notebook interface, select Bash from the 'New' menu
jupyter qtconsole --kernel bash
jupyter console --kernel bash

pipx and "externally managed" environments


A recent-ish `PEP 668 <https://peps.python.org/pep-0668/#guide-users-towards-virtual-environments>`_ recommends that users install Python applications with `pipx` rather than global installs with `pip`. This is strongly suggested/enforced in current Linux distros. Because `bash_kernel` needs an extra step to actually work after installing with `pip` or `pipx`, this causes some inconvenience.

First, one must install the Jupyter ecosystem with pipx, and then inject bash_kernel (and any other bits of the jupyter ecosystem you use, like papermill) into the same pipx venv.

.. code:: shell

    pipx install --include-deps jupyter
    pipx inject --include-apps --include-deps jupyter bash_kernel

One then must manually find the corresponding venv, activate it, and run `python -m bash_kernel.install` *within* that virtual env. If done outside it, this won't work as bash_kernel is not installed in the global environment.

.. code:: shell

    cd ~/.local/pipx/venvs/jupyter/
    source bin/activate
    python -m bash_kernel.install
    deactivate

Of course, one can also install bash_kernel to the global environement thusly:

.. code:: shell

    pip install --break-system-packages juptyer bash_kernel
    python -m bash_kernel.install

Requirements of Bash
~~~~~~~~~~~~~~~~~~~~

Bash kernel directly interacts with bash, and therefore requires a functioning interactive build of bash. In nearly all cases this will be the default, however some distributions remove GNU readline or other interactivity features of bash. Almost always, these features are provided in a separate, more complete bash package, which should be installed. See for example https://github.com/takluyver/bash_kernel/issues/142.

Displaying Rich Content
-----------------------

To use specialized content (images, html, etc) this file defines (in `build_cmds()`) bash functions
that take the contents as standard input. Currently, `display` (images), `displayHTML` (html)
and `displayJS` (javascript) are supported.

Example:

.. code:: shell

    cat dog.png | display
    echo "<b>Dog</b>, not a cat." | displayHTML
    echo "alert('Hello from bash_kernel\!');" | displayJS

Updating Rich Content Cells
---------------------------

If one is doing something that requires dynamic updates, one can specify a unique display_id,
which should be a string name. On each update, the contents will be replaced by the new value. Example:

.. code:: shell

    display_id="id_${RANDOM}"
    ((ii=0))
    while ((ii < 10)) ; do
        echo "<div>${ii}</div>" | displayHTML $display_id
        ((ii = ii+1))
        sleep 1
    done

The same works for images and javascript content.

**Remember to create always a new id** each time the cell is executed, otherwise it will try to display
on an HTML element that no longer exists (they are erased each time a cell is re-run).

Programmatically Generating Rich Content
----------------------------------------

Alternatively one can simply generate the rich content to a file in /tmp (or $TMPDIR)
and then output the corresponding (to the mimetype) context prefix ``"_TEXT_SAVED_*"``
constant. So one can write programs (C++, Go, Rust, etc.) that generates rich content
appropriately, when within a notebook.

The environment variable "NOTEBOOK_BASH_KERNEL_CAPABILITIES" will be set with a comma
separated list of the supported types (currently "image,html,javascript") that a program
can check for.

To output to a particular "display_id", to allow update of content (e.g: dynamically
updating/generating a plot from a command line program), prefix the filename
with "(<display_id>)". E.g: a line to display the contents of /tmp/myHTML.html to
a display id "id_12345" would look like:

    bash_kernel: saved html data to: (id_12345) /tmp/myHTML.html

More Information
----------------

For details of how this works, see the Jupyter docs on `wrapper kernels
<http://jupyter-client.readthedocs.org/en/latest/wrapperkernels.html>`_, and
Pexpect's docs on the `replwrap module
<http://pexpect.readthedocs.org/en/latest/api/replwrap.html>`_.