Snappy previews of Jupyter notebooks from the command line, with ranger integration.
- 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
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 autoInstallation: pipx install git+https://github.com/tnwei/nbread.
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.
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.