Skip to content

Instantly share code, notes, and snippets.

@syrte
Created February 14, 2022 20:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save syrte/97efeef9416d28ba52d6163150b19be9 to your computer and use it in GitHub Desktop.
Save syrte/97efeef9416d28ba52d6163150b19be9 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys
import json
for file in sys.argv[1:]:
print('# file: %s' % file)
print('# vi: filetype=python')
print('')
code = json.load(open(file))
for cell in code['cells']:
if cell['cell_type'] == 'code':
print('# -------- code --------')
for line in cell['source']:
print(line, end='')
print('\n')
elif cell['cell_type'] == 'markdown':
print('# -------- markdown --------')
for line in cell['source']:
print("#", line, end='')
print('\n')
@syrte
Copy link
Author

syrte commented Nov 30, 2023

The code displays jupyter notebook input cells in terminal.
Usage:

nbcat.py my_notebook.ipynb

One can view it in vim

nbcat.py my_notebook.ipynb | view -

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment