Skip to content

Instantly share code, notes, and snippets.

@kastiglione
Last active May 4, 2020 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kastiglione/d17d715c2a4b398a9072576ea8874766 to your computer and use it in GitHub Desktop.
Save kastiglione/d17d715c2a4b398a9072576ea8874766 to your computer and use it in GitHub Desktop.
Change files to be transparently compressed
#!/bin/bash
set -euo pipefail
hfs-compress() {
local files=("$@")
local filepath perms temppath
for filepath in "${files[@]}"; do
perms=$(stat -f %p "$filepath")
chmod +rw "$filepath"
temppath=$(mktemp)
ditto --hfsCompression "$filepath" "$temppath"
mv "$temppath" "$filepath"
chmod "$perms" "$filepath"
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment