Skip to content

Instantly share code, notes, and snippets.

@marcedwards
Forked from ZevEisenberg/moveAssetImages.sh
Created February 25, 2014 05:33
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 marcedwards/9203292 to your computer and use it in GitHub Desktop.
Save marcedwards/9203292 to your computer and use it in GitHub Desktop.
#!/bin/sh
function moveAssetImages
{
usage="usage: moveAssetImages /path/to/folderOfImages /path/to/Images.xcassets"
sourceDir=$1
assetsDir=$2
if [ $# != 2 ]; then
echo $usage
return
fi
if [[ ! -d $sourceDir ]]; then
echo "Directory not found: $sourceDir"
return
fi
if [[ ! -d $assetsDir ]]; then
echo "Directory not found: $assetsDir"
return
fi
echo $assetsDir
if [[ `echo $assetsDir | awk -F . '{print $NF}'` != "xcassets" ]]; then
echo $usage
return
else
for image in $sourceDir/*
do
filename=`basename $image`
extension=`echo $filename | awk -F . '{print $NF}'`
nameWithoutExtension=`basename $image .$extension`
# strip suffixes like ~iPad
if [[ $nameWithoutExtension == *"~"* ]]; then
deviceSuffix=`echo $nameWithoutExtension | sed 's/.*~//'`
nameWithoutExtension=`basename $nameWithoutExtension "~$deviceSuffix"`
fi
# strip suffixes like @2x
nameWithoutExtension=`basename $nameWithoutExtension @2x`
# move files into place
if [[ -e $assetsDir/$nameWithoutExtension.imageset/$filename ]]; then
cp $sourceDir/$filename $assetsDir/$nameWithoutExtension.imageset/$filename
fi
done
fi
}
moveAssetImages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment