-
Notifications
You must be signed in to change notification settings - Fork 3
/
convert_all.sh
executable file
·49 lines (44 loc) · 1.31 KB
/
convert_all.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
# If no arguments were provided, exit with error and show usage.
if [ $# -eq 0 ]; then
echo "Usage: $0 md | ipynb " >&2
exit 1
fi
# Variable to track if any errors occur
error_occurred=0
if [ "$1" = "ipynb" ]; then
files=$(find docs/ -name "*.md" | grep -v .ipynb_checkpoints)
for file in $files; do
# Extract the kernel information from the Jupytext Markdown file
kernel_info=$(head -n 15 "$file" | grep -A 10 '^---$' | grep -E 'kernelspec')
# Skip if no kernel information was found
if [ -z "$kernel_info" ]; then
continue
fi
jupytext --to ipynb "$file" && rm "$file"
if [ $? -ne 0 ]; then
error_occurred=1
echo "Errors when converting $file"
else
echo "Converted $file"
fi
done
elif [ "$1" = "md" ]; then
files=$(find docs/ -name "*.ipynb" | grep -v .ipynb_checkpoints)
for file in $files; do
jupytext --to markdown "$file" && rm "$file"
if [ $? -ne 0 ]; then
error_occurred=1
echo "Errors when converting $file"
else
echo "Converted $file"
fi
done
fi
if [ $error_occurred -ne 0 ]; then
echo "Some files failed to convert." >&2
exit 1
else
echo "All files converted successfully." >&2
exit 0
fi