knoebber / auto_unzip

~/bin/auto-unzip Commits Diff Raw
#!/bin/bash

# Creates directories with names based on zips and unzips.
# Example: Blood Orange - Coastal Grooves.zip => blood_orange_coastal_grooves
# This script is OSX specific - unzip fails on special characters so it uses ditto

find ./*.zip | while read -r zipped
do
    echo "processing $zipped";
    # The name of the directory to unzip the content to.
    # Changes spaces to _, remove non word chars, remove repeating _, change to lowercase
    base=$(basename "$zipped" .zip)
    dir=$(echo "$base"\
              | gsed 's/\s/_/g'\
              | gsed 's/\W//g'\
              | gsed 's/_\+/_/g'\
              | tr '[:upper:]' '[:lower:]'
       )
    echo "create $dir"
    mkdir "$dir"
    ditto -V -x -k --sequesterRsrc --rsrc "$zipped" "$dir"
done