5 ms·
Yep, I write scripts to clean up zip files because the default behavior is so bad for cross-platform.
by makecheck 5y ago
Yep, I write scripts to clean up zip files because the default behavior is so bad for cross-platform.
- smarx007 5y agoCould you please share it?
- makecheck 5y agoThis is my script to “clean up” a typical macOS zip file. It assumes you’ve started by asking the Finder to “Compress” (which creates a zip file but one riddled with macOS-isms). #!/bin/bash zipfile=$1 if [ "x$zipfile" = "x" ] ; then echo "$0: .zip file expected" >&2 exit 1 fi zip -d "${zipfile}" "__MACOSX*" zip -d "${zipfile}" ".DS_Store" zip -d "${zipfile}" "*/.DS_Store" unzip -l "${zipfile}" | sort -k 5
- rahen 5y agoYou probably want to test: if [ ! -f "$zipfile" ] Instead of if [ "x$zipfile" = "x" ]
- xorcist 5y agoProcessing the zip file three times over seems a bit excessive? zip -d "${zipfile}" "__MACOSX*" ".DS_Store" "*/.DS_Store"
- makecheck 5y agoTrue but performance wasn’t the goal (I tend to run it once on smallish files). This is easier to extend if I see something new to exclude (or comment-out some rule).
- smarx007 5y agoThank you! I took your script, suggestions in this thread and added some of my sauce: #!/usr/bin/env bash set -exuo pipefail VERBOSE=false while getopts "v" arg; do case $arg in v) VERBOSE=true;; esac done shift $((OPTIND-1)) zipfile=$1 if [ ! -f "$zipfile" ] || [ ! "${zipfile##*.}" = "zip" ] ; then echo "$0: .zip file expected" >&2 exit 1 fi zip -d "${zipfile}" "__MACOSX*" ".DS_Store" "*/.DS_Store" "Thumbs.db" "*/Thumbs.db" if [ $VERBOSE = true ]; then unzip -l "${zipfile}" | sort -k 5 fi
- bombcar 5y agoBetterZip has an option for “clean” zips you can enable as the default for create.