Skip to content

Instantly share code, notes, and snippets.

@ppdms
Created January 11, 2026 14:24
Show Gist options
  • Select an option

  • Save ppdms/5e9c5807ee3847b842fcab9e01ff658b to your computer and use it in GitHub Desktop.

Select an option

Save ppdms/5e9c5807ee3847b842fcab9e01ff658b to your computer and use it in GitHub Desktop.
#!/usr/bin/env fish
# Script to properly zip all epub directories into epub files
# Uses the correct epub zipping method with uncompressed mimetype
# https://www.mobileread.com/forums/showthread.php?t=55681
set downloads_dir (pwd)
# Find all .epub directories
for epub_dir in *.epub/
# Remove trailing slash
set epub_dir (string trim -r -c / $epub_dir)
if test -d "$epub_dir"
echo "Processing: $epub_dir"
# Output file name (without directory extension)
set output_file (string replace ".epub" "_fixed.epub" $epub_dir)
# Change into the epub directory
cd "$epub_dir"
# Check if mimetype file exists
if not test -f mimetype
echo " ⚠️ Warning: No mimetype file found in $epub_dir"
cd "$downloads_dir"
continue
end
# Remove any existing output file
rm -f "$downloads_dir/$output_file"
# Step 1: Zip mimetype with no compression
echo " - Zipping mimetype (no compression)..."
zip -X0 "$downloads_dir/$output_file" mimetype
# Step 2: Zip everything else with compression, excluding mimetype and .DS_Store
echo " - Zipping remaining files (with compression)..."
zip -rDX9 "$downloads_dir/$output_file" * -x "*.DS_Store" -x mimetype
# Return to downloads directory
cd "$downloads_dir"
echo " ✓ Created: $output_file"
echo ""
end
end
echo "Done! All epub directories have been processed."
echo "Original directories are preserved. Fixed epubs have '_fixed' suffix."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment