Skip to content

Instantly share code, notes, and snippets.

@fish8
Last active February 5, 2021 01:21
Show Gist options
  • Save fish8/49dddc7f598fe526246f9d9a869957d7 to your computer and use it in GitHub Desktop.
Save fish8/49dddc7f598fe526246f9d9a869957d7 to your computer and use it in GitHub Desktop.
jupyter notebook code search and print
#pynb-code, show all codes in a jupyter notebook
jq -j '.cells | map( select(.cell_type == "code") | .source +["\n\n"]) | .[][] ' $@
#beautify code in notebook and copy to clipboard as rich text
pynb-code xxx.ipynb |pygmentize -f rtf | xclip -t text/rtf -selection clipboard
#find print
find . -name "*.ipynb" -exec pynb-code {} +
#find grep
find . -name "*.ipynb" -print|xargs -n1 -I% nbgrep 'sstool' %
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment