Skip to content

Instantly share code, notes, and snippets.

@ZevEisenberg
Created February 25, 2014 05:17
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ZevEisenberg/9203170 to your computer and use it in GitHub Desktop.
Save ZevEisenberg/9203170 to your computer and use it in GitHub Desktop.
Shell script to move a folder of correctly-named image files into their respective .xcassets subfolders
#!/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