Last active
December 2, 2015 14:06
-
-
Save Altreus/0bee9624daf3a76f1044 to your computer and use it in GitHub Desktop.
Unzip with splurge protection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sunzip() { | |
unzip -l "$1" | \ | |
head -n -2 | \ | |
tail -n +4 | \ | |
perl -lnE'$dirs{((split " ")[3] =~ m!([^/]*)!)[0]}++ } { exit 1 if keys %dirs > 1' | |
if [[ "$?" -eq "0" ]]; then | |
unzip "$1" | |
else | |
EXDIR="${1/%.zip/}" | |
mkdir "$EXDIR" | |
unzip -d "$EXDIR" "$1" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment