Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .gitlint
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ contrib=contrib-title-conventional-commits

[contrib-title-conventional-commits]
# Specify allowed commit types. For details see: https://www.conventionalcommits.org/
types = feat, fix, chore, docs, test, refactor, update, merge, explore

types = feat, fix, chore, docs, test, refactor, update, merge, explore, style
29 changes: 19 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v4.0.1"
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v6.0.0"
hooks:
- id: check-ast
- id: check-json
- id: check-yaml
- repo: https://github.com/psf/black
rev: "21.9b0"
- id: check-ast
- id: check-json
- id: check-yaml
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.14.10
hooks:
- id: black
- repo: https://github.com/jorisroovers/gitlint
rev: "v0.15.1"
# Equivalent to isort
- id: ruff
args: ["--select", "I", "--fix"]
# Formatter, replaces black
- id: ruff-format
types_or: [python, pyi, jupyter]
- repo: https://github.com/jorisroovers/gitlint
rev: "v0.19.1"
hooks:
- id: gitlint
args: [--msg-filename]
10 changes: 5 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Changelog

## Unreleased
## 0.2.0 (Jan 1, 2026)

+ Update `--paging` option to `--no-pager` and honor $PAGER to be more Unix-like
+ Print placeholders for non-text cell output (images and javascript), pretty prints specific text types (latex, json, html)
+ Remove cell borders to be copy-paste friendly
+ Show images with sixel using --experimental-images
+ Update `--paging` option to `--no-pager` and honor $PAGER to be more Unix-like (#6)
+ Print placeholders for non-text cell output (images and javascript), pretty prints specific text types (latex, json, html) (#7)
+ Remove cell borders to be copy-paste friendly (#8)
+ Show images with sixel using --experimental-images (#9)

## 0.1.2dev1 (Mar 7, 2024)

Expand Down
53 changes: 18 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# nbread

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

<p align="center">
<img width="800" src="https://raw.githubusercontent.com/tnwei/nbread/main/nbread-cast.svg">
Expand All @@ -13,7 +13,7 @@ Snappy previews of Jupyter notebooks from the command line, with ranger integrat

## Usage

Run `nbread notebook.ipynb` for notebook preview in terminal.
Run `nbread notebook.ipynb` for notebook preview in terminal.

```bash
$ nbread --help
Expand All @@ -32,12 +32,16 @@ Paging: Defaults to 'less' with auto-exit. Override with $PAGER env var or
disable with --no-pager. Set PAGER='' to disable paging via environment.
```

Try it out with the notebooks bundled in `tests/`!

### Experimental: Image Support

nbread supports rendering images in notebooks using Sixel graphics. This feature is experimental and requires:
![](docs/sixel.png)

`nbread` supports rendering images in notebooks using Sixel graphics. This feature is experimental and requires:

- A Sixel-compatible terminal (e.g., `xterm`, `mlterm`, `foot`, `wezterm`, `konsole`, `contour`)
- `chafa` installed (install via your package manager: `sudo apt install chafa`, `brew install chafa`, etc.)
- A Sixel-compatible terminal (e.g., `xterm`, `mlterm`, `foot`, `wezterm`, `konsole`, `contour`). Check [Are We Sixel Yet](https://www.arewesixelyet.com/) for a latest up-to-date list
- `chafa` installed (install via your package manager: `sudo apt install chafa`, `brew install chafa`, `sudo dnf install chafa` etc.)

To enable image rendering:

Expand All @@ -49,42 +53,21 @@ nbread --experimental-images notebook.ipynb

## 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:
One of the following:

If your `~/.config/ranger/` dir is empty, run `ranger --copy-config=all` to populate it w/ the defaults.
`pip install git+https://github.com/tnwei/nbread`

Enabling panel preview when a notebook is highlighted: modify `handle_extension()` in `~/.config/ranger/scope.sh`:
`pipx install git+https://github/com/tnwei/nbread`

```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:
```
`uv tool install git+https://github/com/tnwei/nbread`

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

```
### INSERT START
# Jupyter notebooks
ext ipynb = nbread "$1"
### INSERT END
```
- [ranger](docs/ranger.md)
- [lf](docs/lf.md)
- [pistol](docs/pistol.md)

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 <notebook.ipynb>` with some speed tweaks and standalone packaging for convenience.

Code heavily based on [Textualize/rich-cli](https://github.com/Textualize/rich-cli)'s notebook pretty printing.
64 changes: 64 additions & 0 deletions docs/lf.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# lf integration

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

_last tested on lf r40_


## Prerequisites

1. If your `~/.config/lf/` dir doesn't exist, create it with `mkdir -p ~/.config/lf` and initialize your config by copying `/etc/lfrc.example` from `github.com/gokechan/lf` as `~/.config/lf/lfrc`

2. (Experimental images) If you want image preview:
- Make sure you have `set sixel true` in `~./config/lf/lfrc`

## Using a dedicated previewer / file opener

Note: If you're using `lf`, high chances are you are using a dedicated previewer / file opener. Follow their own instructions instead.

## Using your own previewer

1. Configure location of your previewer script in `~/.config/lf/lfrc` if you don't have one already:

```
+ set previewer ~/.config/lf/previewer
```

2. Modify `~/.config/lf/previewer` with the following content:

```bash
#!/bin/sh

case "$1" in
*.ipynb)
nbread "$1"
;;
*)
# Fallback for other file types
cat "$1"
;;
esac
```

3. Make the previewer script executable:

```bash
chmod +x ~/.config/lf/previewer
```

## Using your own file opener

1. Add the following to `~/.config/lf/lfrc` to open Jupyter notebooks with `nbread`:

```
# Jupyter notebooks
cmd open ${{
case "$f" in
*.ipynb) nbread "$f" ;;
*) $OPENER "$f" ;;
esac
}}
```

2. (Experimental images) If you want image preview:
- Modify Step 5 to use `nbread --experimental-images "$f"`
34 changes: 34 additions & 0 deletions docs/pistol.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Pistol integration

Pistol is a file previewer for command-line file managers like ranger and lf.

_last tested on pistol 0.5.3_

## Configuration

Add the following to `~/.config/pistol/pistol.conf`:

```
fpath .*\.ipynb$ nbread --experimental-images %pistol-filename%
```

**Note:** Pistol matches rules in order and stops at the first match. If you have other rules that might match `.ipynb` files (like a general JSON handler), make sure to place the nbread rule before them in your config file.

## Usage with file managers

### With lf

Set pistol as your previewer in `~/.config/lf/lfrc`:

```
set previewer pistol
```

### With ranger

Set pistol as your previewer in `~/.config/ranger/rc.conf`:

```
set preview_script ~/.config/pistol/pistol
set use_preview_script true
```
31 changes: 31 additions & 0 deletions docs/ranger.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Ranger integration

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

_last tested on ranger 1.9.4_


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

2. Add the following to `handle_extension()` in `~/.config/ranger/scope.sh` to enable panel preview:

```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:
```

3. Add the following to `~/.config/ranger/rifle.conf` to enable fullscreen preview:

```
### INSERT START
# Jupyter notebooks
ext ipynb, has nbread, label nbread, terminal = nbread "$@"
### INSERT END
```
Binary file added docs/sixel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading