Ipylivebash - Run shell script in Jupyter with live output

Overview

ipylivebash

ipylivebash is a library to run shell script in Jupyter with live output.

Example

%%livebash --save log.txt --save-timestamp

find .

Run find . and show the output in the Jupyter notebook and also save to log-${current_timestamp}.txt

%%livebash --ask-confirm --notify
set -e
deploy_script

Before running the deploy_script show a panel to ask for confirmation. Once it is finished, show a notification.

Features

  1. Run shell script in Jupyter with live output
  2. The output in the notebook cell is not saved in the notebook by default
  3. Support to save the output to a file. If the file already exists, it will pick another name automatically.
  4. Support to show a confirmation UI before executing the script
  5. Support to send a notification when the script finishes.

Usage

usage: livebash [-h] [--save OUTPUT_FILE] [--save-timestamp]
                [--line-limit LINE_LIMIT] [--height HEIGHT] [--ask-confirm]
                [--notify] [--keep-cell-output]

optional arguments:
  -h, --help
  --save OUTPUT_FILE    Save output to a file
  --save-timestamp      Add timestamp to the output file name
  --line-limit LINE_LIMIT
                        Restrict the no. of lines to be shown
  --height HEIGHT       Set the height of the output cell
  --ask-confirm         Ask for confirmation before execution
  --notify              Send a notification when the script finished
  --keep-cell-output    Keep the cell output

Options

--save OUTPUT_FILE

Save the output to a file.

If the file name already exists, it will add a suffix to avoid overriding the original file.

--save-timestamp

Add timestamp to the output file name.

--line-limit LINE_LIMIT

If the no. of line output exceed the limit, it may be truncated. It will show the last 5 lines only.

--height HEIGHT

Set the height of the output cell

--ask-confirm

Ask for confirmation before execution

ask_confirm.png (392×80)

--notify

Send a notification when the script finished

--keep-cell-output

Keep the cell output such that it could be saved together with the notebook. It can't be used with other options like --line-limit.

Installation

You can install using pip:

pip install ipylivebash

If you are using Jupyter Notebook 5.2 or earlier, you may also need to enable the nbextension:

jupyter nbextension enable --py [--sys-prefix|--user|--system] ipylivebash

Development Installation

Create a dev environment:

conda create -n ipylivebash-dev -c conda-forge nodejs yarn python jupyterlab
conda activate ipylivebash-dev

Install the python. This will also build the TS package.

pip install -e ".[test, examples]"

When developing your extensions, you need to manually enable your extensions with the notebook / lab frontend. For lab, this is done by the command:

jupyter labextension develop --overwrite .
yarn run build

For classic notebook, you need to run:

jupyter nbextension install --sys-prefix --symlink --overwrite --py ipylivebash
jupyter nbextension enable --sys-prefix --py ipylivebash

Note that the --symlink flag doesn't work on Windows, so you will here have to run the install command every time that you rebuild your extension. For certain installations you might also need another flag instead of --sys-prefix, but we won't cover the meaning of those flags here.

How to see your changes

Typescript:

If you use JupyterLab to develop then you can watch the source directory and run JupyterLab at the same time in different terminals to watch for changes in the extension's source and automatically rebuild the widget.

# Watch the source directory in one terminal, automatically rebuilding when needed
yarn run watch
# Run JupyterLab in another terminal
jupyter lab

After a change wait for the build to finish and then refresh your browser and the changes should take effect.

Python:

If you make a change to the python code then you will need to restart the notebook kernel to have it take effect.

You might also like...
Output Analyzer for you terminal commands
Output Analyzer for you terminal commands

Output analyzer (OZER) You can specify a few words inside config.yaml file and specify the color you want to be used. installing: Install command usin

Python Processing Tool for Vasp Ipnut/Output
Python Processing Tool for Vasp Ipnut/Output

PivotPy A Python Processing Tool for Vasp Input/Output. A CLI is available in Powershell, see Vasp2Visual. stylea{text-decoration: none !important;c

Runs a command in P4wnP1 and displays the output on OLED screen (SH1106)

p4wnp1-oled-terminal Runs a command in P4wnP1 and displays the output on OLED screen (SH1106) Works on Raspberry Pi Zero 2 W Tested successfully on RP

Tablicate - Python library for easy table creation and output to terminal

Tablicate Tablicate - Python library for easy table creation and output to terminal Features Column-wise justification alignment (left, right, center)

Format click help output nicely with rich.
Format click help output nicely with rich.

rich-click Format click help output nicely with Rich. Click is a "Python package for creating beautiful command line interfaces". Rich is a "Python li

xonsh is a Python-powered, cross-platform, Unix-gazing shell
xonsh is a Python-powered, cross-platform, Unix-gazing shell

xonsh is a Python-powered, cross-platform, Unix-gazing shell language and command prompt.

adds flavor of interactive filtering to the traditional pipe concept of UNIX shell

percol __ ____ ___ ______________ / / / __ \/ _ \/ ___/ ___/ __ \/ / / /_/ / __/ / / /__/ /_/ / / / .__

xonsh is a Python-powered, cross-platform, Unix-gazing shell language and command prompt.
xonsh is a Python-powered, cross-platform, Unix-gazing shell language and command prompt.

xonsh xonsh is a Python-powered, cross-platform, Unix-gazing shell language and command prompt. The language is a superset of Python 3.6+ with additio

Fetch is use to get information about anything on the shell using Wikipedia.
Fetch is use to get information about anything on the shell using Wikipedia.

Fetch Search wikipedia article on command line [Why This?] [Support the Project] [Installation] [Configuration] Why this? Fetch helps you to quickly l

Comments
  • Problem in kubectl outputs

    Problem in kubectl outputs

    HI,

    first of all: thanks for this extesion, it helps a lot.

    But there seems to be an issue if the output comes too fast or something. It might be the debouncing? The output is only printed after I terminate the line or a new pod is created.

    %%livebash
    kubectl get pods -w
    

    It works if I use the following code:

    import subprocess
    import shlex
    def run_command(command):
        process = subprocess.Popen(shlex.split(command), stdout=subprocess.PIPE)
        while True:
            output = process.stdout.readline()
            if output == '' and process.poll() is not None:
                break
            if output:
                print(output.strip().decode("utf-8") )
        rc = process.poll()
        return rc
    
    run_command("kubectl get pods -w")
    
    opened by smerschjohann 2
Releases(release/0.1.2)
Owner
Ben Lau
Full Stack Developer
Ben Lau
A CLI Password Manager made using Python and Postgresql database.

ManageMyPasswords (CLI Edition) A CLI Password Manager made using Python and Postgresql database. Quick Start Guide First Clone The Project git clone

Imira Randeniya 1 Sep 11, 2022
jrnl is a simple journal application for the command line.

jrnl To get help, submit an issue on Github. jrnl is a simple journal application for the command line. You can use it to easily create, search, and v

jrnl 5.7k Dec 31, 2022
A Python script for finding a food-truck based on latitude and longitude coordinates that you can run in your shell

Food Truck Finder Project Description This repository contains a Python script for finding a food-truck based on latitude and longitude coordinates th

1 Jan 22, 2022
instant coding answers via the command line

howdoi instant coding answers via the command line Sherlock, your neighborhood command-line sloth sleuth. Are you a hack programmer? Do you find yours

Benjamin Gleitzman 9.8k Jan 08, 2023
Calculator for CLI. Made with Python

Calculator for CLI. Made with Python

Brandon Arreguin 2 Jan 07, 2022
Simple command line tool for text to image generation using OpenAI's CLIP and Siren (Implicit neural representation network)

Simple command line tool for text to image generation using OpenAI's CLIP and Siren (Implicit neural representation network)

Phil Wang 4.4k Jan 09, 2023
A simple Python library that allows you to customize your CLI based output on Linux

Terminal-Colored-Print About A small module that allows to simply decorate strings on Linux terminals. I personally use it for multi-threaded project,

Francesco Milano 0 Dec 13, 2021
Terminal with builtin ortholinear keyboard and touch screen as a home automation interface.

OLKB-Terminal Terminal with builtin ortholinear keyboard and touch screen as a home automation interface. Features Step and STLs available for non-com

Jeff Eberl 50 Oct 07, 2022
Oil is a new Unix shell. It's our upgrade path from bash to a better language and runtime

Oil is a new Unix shell. It's our upgrade path from bash to a better language and runtime. It's also for Python and JavaScript users who avoid shell!

2.4k Jan 08, 2023
EODAG is a command line tool and a plugin-oriented Python framework for searching, aggregating results and downloading remote sensed images while offering a unified API for data access regardless of the data provider

EODAG (Earth Observation Data Access Gateway) is a command line tool and a plugin-oriented Python framework for searching, aggregating results and downloading remote sensed images while offering a un

CS GROUP 205 Jan 03, 2023
A simple weather tool. I made this as a way for me to learn Python, API, and PyPi packaging.

A simple weather tool. I made this as a way for me to learn Python, API, and PyPi packaging.

Clint E. 105 Dec 31, 2022
iTerm2 Shell integration for Xonsh shell.

iTerm2 Shell Integration iTerm2 Shell integration for Xonsh shell. Installation To install use pip: xpip install xontrib-iterm2 # or: xpip install -U

Noorhteen Raja NJ 6 Dec 29, 2022
Dart Version Manager CLI implemented with Python and Typer.

Dart Version Manager Dart Version Manager CLI implemented with Python and Typer Usage: $ dvm [OPTIONS] COMMAND [ARGS]... Options: --install-completion

EducUp 6 Jun 26, 2022
Text based command line webcam photobooth app

Skunkbooth Why See it in action Usage Installation Run Media location Contributing Install Poetry Clone the repo Activate poetry shell Install dev dep

David Yang 45 Dec 26, 2022
GDBIGtools: A command line tools for GDBIG varaints browser

GDBIGtools: A command line tools for GDBIG varaints browser Introduction Born in Guangzhou Cohort Study Genome Research Database is based on thousands

广州市出生队列基因组学研究(The genomics study of BIGCS) 7 Sep 14, 2022
Juniper Command System is a Micro CLI Tool that allows you to manage your files, launch applications, as well as providing extra tools for OS Management.

Juniper Command System is a Micro CLI Tool that allows you to manage your files, launch applications, as well as providing extra tools for OS Management.

Juan Carlos Juárez 1 Feb 02, 2022
A python based command line tool to compare Github Users or Repositories

gitcomp A simple python package with a CLI to compare GitHub users and repositories by associating a git_score to each entry which is a weighted sum o

Anirudh Vaish 5 Mar 26, 2022
Command line, configuration and persistence utilities

Zensols Utilities Command line, configuration and persistence utilities generally used for any more than basic application. This general purpose libra

Paul Landes 2 Nov 17, 2022
A CLI tool that scans through a directory and organizes all loose files into folders by file type.

Organizer CLI Organizer CLI is a python command line tool that goes through a given directory and organizes all un-folder bound files into folders by

Mulaza Jacinto 6 Dec 14, 2022
Salesforce object access auditor

Salesforce object access auditor Released as open source by NCC Group Plc - https://www.nccgroup.com/ Developed by Jerome Smith @exploresecurity (with

NCC Group Plc 90 Sep 19, 2022