Last active
March 20, 2023 19:18
-
-
Save jonahpearl/5bd84ee032911ee0b0c32f773a9b511e to your computer and use it in GitHub Desktop.
Re-indent directory of ipynb's
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
# Will convert all files in current dir, recursively. Could be modified to take args but I'm lazy! | |
for filename in ./**/*.ipynb; do | |
# Split the file name | |
extension="${filename##*.}"; | |
filename_noext="${filename%.*}"; | |
# Convert ipynb to text | |
jupytext --to py -o "${filename_noext}_script.py" "${filename}" | |
# Re-indent (eg 2 spaces per tab --> 4 spaces per tab) | |
reindent -rn "${filename_noext}_script.py" # recursive, no backup | |
# Re-make ipynb from re-indented script | |
jupytext --to ipynb -o "${filename_noext}.ipynb" "${filename_noext}_script.py" | |
# Remove intermediate output | |
rm "${filename_noext}_script.py" | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See:
reindent
jupytext