Skip to content

Commit abebbf9

Browse files
committed
Pretty-print JSON if possible, refs #3
1 parent 7a2fe3d commit abebbf9

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

download.sh

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ fi
5050
TEMP_FILE=$(mktemp)
5151

5252
# Download the file
53-
echo "Downloading $URL..."
53+
echo "Downloading $URL"
5454
curl -s -L "$URL" -o "$TEMP_FILE" || {
5555
echo "Error: Failed to download $URL"
5656
rm -f "$TEMP_FILE"
@@ -75,6 +75,21 @@ fi
7575
CURRENT_DIR="$(pwd)"
7676
FULL_PATH="${CURRENT_DIR}/${FILENAME}"
7777

78+
# Pretty-print JSON if applicable
79+
if [ "$EXTENSION" = ".json" ]; then
80+
# Create another temporary file for the pretty-printed version
81+
PRETTY_TEMP=$(mktemp)
82+
# Try to pretty-print with jq, but don't fail if jq fails
83+
if command -v jq &> /dev/null; then
84+
if jq . "$TEMP_FILE" > "$PRETTY_TEMP" 2>/dev/null; then
85+
mv "$PRETTY_TEMP" "$TEMP_FILE"
86+
else
87+
rm -f "$PRETTY_TEMP"
88+
fi
89+
else
90+
rm -f "$PRETTY_TEMP"
91+
fi
92+
fi
93+
7894
# Move to final destination
7995
mv "$TEMP_FILE" "$FULL_PATH"
80-

0 commit comments

Comments
 (0)