#!/bin/sh
set -e
command -v jq > /dev/null || exec guix shell jq -- "$0" "$@"
if [ $# -lt 1 ]; then
exec find . -name "*.ipynb" -and '!' -wholename "*/.ipynb_checkpoints/*" \
-exec "$0" '{}' \;
fi
for NOTEBOOK in "$@"; do
TMP="$(printf %s "$NOTEBOOK" | sed 's/[.]ipynb$/-TMP.ipynb/')"
jq --indent 1 --sort-keys '
. + {
cells: [
.cells[] |
(. +
if .cell_type == "code" then
{outputs: [], execution_count: null}
else
{}
end)
]
}
' < "$NOTEBOOK" > "$TMP"
mv "$TMP" "$NOTEBOOK"
done
