https://github.com/tnwei/nbread
Snappy previews of Jupyter notebooks from the command line, with ranger integration
https://github.com/tnwei/nbread
data-science jupyter python ranger
Last synced: about 1 year ago
JSON representation
Snappy previews of Jupyter notebooks from the command line, with ranger integration
- Host: GitHub
- URL: https://github.com/tnwei/nbread
- Owner: tnwei
- License: mit
- Created: 2022-12-31T02:52:07.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-06-17T13:58:15.000Z (about 2 years ago)
- Last Synced: 2025-04-22T23:50:08.087Z (about 1 year ago)
- Topics: data-science, jupyter, python, ranger
- Language: Python
- Homepage:
- Size: 41 KB
- Stars: 8
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# nbread
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.
```bash
$ 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`:
```bash
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](https://github.com/Textualize/rich-cli)'s notebook pretty printing. This is pretty much `rich ` with some speed tweaks and standalone packaging for convenience.