Giter VIP home page Giter VIP logo

nbread's Introduction

nb-read

Snappy previews of Jupyter notebooks from the command line, with ranger integration.

Use case

  • Read notebooks using just the terminal, don't need to spin up a Jupyter Notebook / Lab instance
  • Read superlarge notebooks without chugging Jupyter Notebook / Lab

Usage

Run nbread notebook.ipynb for notebook preview in terminal.

$ nbread --help
usage: nbread [-h] [--paging PAGING] filename

positional arguments:
  filename

optional arguments:
  -h, --help       show this help message and exit
  --paging PAGING  Specify when to use the pager [auto/never/always], defaults to auto

Setup

Installation: pipx install git+https://github.com/tnwei/nbread.

Ranger integration

Use ranger as normal, and see Jupyter notebook previews in place of the underlying JSON plain text!

Do the following for ranger integration:

If your ~/.config/ranger/ dir is empty, run ranger --copy-config=all to populate it w/ the defaults.

Enabling panel preview when a notebook is highlighted: modify handle_extension() in ~/.config/ranger/scope.sh:

handle_extension(){
    case "${FILE_EXTENSION_LOWER}" in
        ### INSERT START
        ipynb)
        ¦   # Jupyter notebook previewer
            nbread "${FILE_PATH}" && { dump | trim; exit 5; } || exit 2;;
        ### INSERT END

        # Archive extensions:

Enabling fullscreen preview in terminal when a notebook is selected: add the following to ~/.config/ranger/rifle.conf:

### INSERT START
# Jupyter notebooks
ext ipynb  = nbread "$1" --pager
### INSERT END

Last tested on ranger 1.9.3, requires less installed.

Appreciation

Code heavily based on Textualize/rich-cli's notebook pretty printing. This is pretty much rich <notebook.ipynb> with some speed tweaks and standalone packaging for convenience.

nbread's People

Contributors

tnwei avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

nbread's Issues

Borderless mode

Having a borderless mode will make it easier to copy and paste text. Currently, the symbols for the cell boundaries will be printed out as well.

Automatically pipe to pager as required

Currently the nbread CLI prints output to less if and only if --pager is explicitly passed. Figured can improve upon this by piping to less if the output will exceed one page, and simply printing to STDOUT if the output will fit in the current window.

Add support for other output types

Currently nbread only supports rendering code cells and markdown cells. Images and interactive JS objects can't be rendered on most terminals, but at least a placeholder can be rendered so that the cell is not simply missing.

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.