Last active
August 21, 2023 03:48
-
-
Save harcoPro/c2c7f70e48ac978245e8 to your computer and use it in GitHub Desktop.
This script renames raw scetch icons via android guidelines and move them into dpi folders
This file contains 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
#!/bin/bash | |
#Скрипт положить в папку с проектом | |
#This is script move to root folder project | |
#current dir | |
currentPath=${PWD} | |
#folder with resource in project | |
resPath=$currentPath/app/src/main/res | |
createDrawableFoldersIfNotExists() | |
{ | |
if [ ! -d "$resPath/drawable-$1" ]; | |
then mkdir "$resPath/drawable-$1" | |
echo "Create the folder $resPath/drawable-$1" | |
fi | |
} | |
if [ ! -z "$1" ] | |
then nameFolder=$1 #path to folder with icons | |
echo "$nameFolder" | |
else echo "Error! setup in argument path to folder with icons" | |
exit 0 | |
fi | |
rm -f $nameFolder/log.txt | |
find $nameFolder -name \*x.png -or -name \*x.PNG >> $nameFolder/log.txt | |
createDrawableFoldersIfNotExists "mdpi" | |
createDrawableFoldersIfNotExists "hdpi" | |
createDrawableFoldersIfNotExists "xhdpi" | |
createDrawableFoldersIfNotExists "xxhdpi" | |
createDrawableFoldersIfNotExists "xxxhdpi" | |
while read line; do | |
#densety=`echo "$line" | grep -o -P '(?<=@).*(?=x.png)'` | |
densety=`echo "$line" | sed 's|^.*@||g' | sed 's|x.png$||g'` | |
rawNameFile=`echo "$line" | tr '[:upper:]' '[:lower:]' | sed 's/ /_/g' | cut -f1 -d"@" | sed 's/\([a-z]\)\([0-9]\)/\1_\2/g' | sed 's/\([0-9]\)\([a-z]\)/\1_\2/g'` | |
for w in $(echo "$rawNameFile" | tr "/" " ") ; do name=$w; done | |
name="ic_$name.png" | |
dpi="-1" | |
if [ "$densety" = "1" ] | |
then dpi="mdpi" | |
echo "$rawNameFile is MDPI" | |
elif [ "$densety" = "1,5" ] | |
then dpi="hdpi" | |
echo "$rawNameFile is HDPI" | |
elif [ "$densety" = "2" ] | |
then dpi="xhdpi" | |
echo "$rawNameFile is XHDPI" | |
elif [ "$densety" = "3" ] | |
then dpi="xxhdpi" | |
echo "$rawNameFile is XXHDPI" | |
elif [ "$densety" = "4" ] | |
then dpi="xxxhdpi" | |
echo "$rawNameFile is XXXHDPI" | |
else | |
echo "Error! The file $rawNameFile don't contains coefficient densety!" | |
fi | |
cp -u "$line" "$resPath/drawable-$dpi/$name" | |
echo "$line copy to $resPath/drawable-$dpi/$name" | |
done < $nameFolder/log.txt | |
rm -f $nameFolder/log.txt | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment