Skip to main content

A bash kernel for Jupyter

Project description

https://mybinder.org/badge_logo.svg

A Jupyter kernel for bash

Installation

This requires IPython 3.

pip install bash_kernel
python -m bash_kernel.install

To use it, run one of:

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

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:

cat dog.png | display
echo "<b>Dog</b>, not a cat." | displayHTML
echo "alert('It is known khaleesi\!');" | displayJS

Updating Rich Content Cells

If one is doing something that requires dynamic updates, one can specify a unique display_id, should be a string name (downstream documentation is not clear on this), and the contents will be replaced by the new value. Example:

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 or even javascript content.

Remember to create always a new id (random ids works perfect) 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, and Pexpect’s docs on the replwrap module.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bash_kernel-0.9.2.tar.gz (617.7 kB view details)

Uploaded Source

Built Distribution

bash_kernel-0.9.2-py2.py3-none-any.whl (617.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file bash_kernel-0.9.2.tar.gz.

File metadata

  • Download URL: bash_kernel-0.9.2.tar.gz
  • Upload date:
  • Size: 617.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.28.1

File hashes

Hashes for bash_kernel-0.9.2.tar.gz
Algorithm Hash digest
SHA256 81bd6bae3d980d208fee10d8b003e071d972ff02fdfebcae0b7d7c2be4c18b39
MD5 4fab3927e53fca56a58cd8e6936ac114
BLAKE2b-256 ca4e2e99e29664858eb1276063827200aad3a979ee0a2e777248b817b8d930ce

See more details on using hashes here.

File details

Details for the file bash_kernel-0.9.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for bash_kernel-0.9.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ae943f5d20a534d53c33260d9ed4d8b2a840f74046a22eddd380ed8984042793
MD5 e8b39b0c7263d1c108641dd9a2b28c4d
BLAKE2b-256 d55501c7a061d5ea680415c005e5c4414fd95abff3f939bdb13448086df9e60e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page