Skip to content

Instantly share code, notes, and snippets.

@Altreus
Last active December 2, 2015 14:06
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 Altreus/0bee9624daf3a76f1044 to your computer and use it in GitHub Desktop.
Save Altreus/0bee9624daf3a76f1044 to your computer and use it in GitHub Desktop.
Unzip with splurge protection
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