Code Monkey home page Code Monkey logo

bash_kernel's Introduction

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.