Skip to content

Instantly share code, notes, and snippets.

@mblarsen
Last active July 27, 2016 12:49
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 mblarsen/e34b68763a7646e40a485ca36f07c089 to your computer and use it in GitHub Desktop.
Save mblarsen/e34b68763a7646e40a485ca36f07c089 to your computer and use it in GitHub Desktop.
Re-zips github repo zipfile so that the first fold is not the repo name but the actual src
#!/bin/bash
# Moves Github zipped-repo files into root of zip files
#
# knockout-master.zip:
#
# knockout-master/<all files>
#
# to:
#
# <all files>
#
githubZipFix() {
OLDWD=`pwd`
FILE=`basename $1`
FILEPATH=`dirname $1`
REALPATH=`cd $FILEPATH ; pwd`
REPO=${FILE%.zip}
TEMP=$(mktemp -d -t $REPO)
echo "Backup file: /tmp/"$FILE
# Backup
cp $1 "/tmp/"$FILE
# Unzip and remove original
unzip $1 -d $TEMP > /dev/null || exit 1
rm $1
# Move dires around and zip
cd $TEMP
mv $REPO/* .
rm -rf $REPO || exit 1
zip $REALPATH"/"$FILE -r * > /dev/null || exit 1
cd $OLDWD
}
alias gfix=githubZipFix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment