Created
December 21, 2017 12:51
-
-
Save W-Floyd/46ed09b83d61a4043d329a119b761796 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
replace_baseplate_circle () { | |
if ! [ -e "${1}" ]; then | |
return 1 | |
fi | |
grep -qE '^ <linearGradient id="linearGradient[0-9]*" x1="1" x2="47" gradientUnits="userSpaceOnUse">$' < "${1}" || return 1 | |
grep -qE '^ <g transform="matrix\(0,-1,1,0,0,48\)' < "${1}" || return 1 | |
local __gradient_number="$(grep -E '^ <linearGradient id="linearGradient[0-9]*" x1="1" x2="47" gradientUnits="userSpaceOnUse">' < "${1}" | grep -oE 'id="linearGradient[0-9]*"' | sed 's/^id="linearGradient\([0-9]*\)"$/\1/')" | |
sed \ | |
-e 's/ <linearGradient id="linearGradient\([0-9]*\)" x1="1" x2="47" gradientUnits="userSpaceOnUse">/ <linearGradient id="linearGradient\1" x2="0" y1="47" y2="1" gradientUnits="userSpaceOnUse">/' \ | |
-i "${1}" | |
perl -i -p0e 's/ <g transform="matrix\(0,-1,1,0,0,48\)".*? <\/g>/ <circle cx="24" cy="24" r="23" style="fill:url\(#GRADIENT_TEMPORARY\)"\/>/s' "${1}" | |
sed -e "s/GRADIENT_TEMPORARY/linearGradient${__gradient_number}/" -i "${1}" | |
echo "${1}" | |
} | |
replace_baseplate_square () { | |
if ! [ -e "${1}" ]; then | |
return 1 | |
fi | |
grep -qE '^ <linearGradient id="linearGradient[0-9]*" x1="-47" x2="-1" y1="2.8779e-15" y2="6.1232e-17" gradientUnits="userSpaceOnUse">$' < "${1}" || return 1 | |
grep -qE '^ <rect transform="rotate\(-90\)" x="-47" y="1" width="46" height="46" rx="4" style="fill:url\(#linearGradient[0-9]*\)' < "${1}" || return 1 | |
pcregrep -qM ' <g transform="translate\(0 3.949e-5\)"> | |
<path d="m1 43v0.25c0 2.216 1.784 4 4 4h38c2.216 0 4-1.784 4-4v-0.25c0 2.216-1.784 4-4 4h-38c-2.216 0-4-1.784-4-4zm0 0.5v0.5c0 2.216 1.784 4 4 4h38c2.216 0 4-1.784 4-4v-0.5c0 2.216-1.784 4-4 4h-38c-2.216 0-4-1.784-4-4z" style="opacity:.02"\/> | |
<path d="m1 43.25v0.25c0 2.216 1.784 4 4 4h38c2.216 0 4-1.784 4-4v-0.25c0 2.216-1.784 4-4 4h-38c-2.216 0-4-1.784-4-4z" style="opacity:.05"\/> | |
<path d="m1 43v0.25c0 2.216 1.784 4 4 4h38c2.216 0 4-1.784 4-4v-0.25c0 2.216-1.784 4-4 4h-38c-2.216 0-4-1.784-4-4z" style="opacity:.1"\/> | |
<\/g>' < "${1}" || return 1 | |
pcregrep -qM ' <g transform="translate\(0 3.949e-5\)"> | |
<g transform="translate\(0 -1004.4\)"> | |
<path d="m1 1043.4v4c0 2.216 1.784 4 4 4h38c2.216 0 4-1.784 4-4v-4c0 2.216-1.784 4-4 4h-38c-2.216 0-4-1.784-4-4z" style="opacity:.1"\/> | |
<\/g> | |
<\/g>' < "${1}" || return 1 | |
local __gradient_number="$(grep -E '^ <linearGradient id="linearGradient[0-9]*" x1="-47" x2="-1" y1="2.8779e-15" y2="6.1232e-17" gradientUnits="userSpaceOnUse">' < "${1}" | grep -oE 'id="linearGradient[0-9]*"' | sed 's/^id="linearGradient\([0-9]*\)"$/\1/')" | |
sed \ | |
-e 's/ y1="2.8779e-15" y2="6.1232e-17" / /' \ | |
-e 's/ <linearGradient id="linearGradient\([0-9]*\)" x1="-47" x2="-1" gradientUnits="userSpaceOnUse">/ <linearGradient id="linearGradient\1" x2="0" y1="47" y2="1" gradientUnits="userSpaceOnUse">/' \ | |
-e 's/ <rect transform="rotate(-90)" x="-47" y="1" width="46" height="46" rx="4" style="fill:url(#linearGradient\([0-9]*\))"\/>/ <rect x="1" y="1" width="46" height="46" rx="4" style="fill:url(#linearGradient\1)"\/>/' \ | |
-i "${1}" | |
perl -i -p0e 's/ <g transform="translate\(0 3.949e-5\)"> | |
<path d="m1 43v0.25c0 2.216 1.784 4 4 4h38c2.216 0 4-1.784 4-4v-0.25c0 2.216-1.784 4-4 4h-38c-2.216 0-4-1.784-4-4zm0 0.5v0.5c0 2.216 1.784 4 4 4h38c2.216 0 4-1.784 4-4v-0.5c0 2.216-1.784 4-4 4h-38c-2.216 0-4-1.784-4-4z" style="opacity:.02"\/> | |
<path d="m1 43.25v0.25c0 2.216 1.784 4 4 4h38c2.216 0 4-1.784 4-4v-0.25c0 2.216-1.784 4-4 4h-38c-2.216 0-4-1.784-4-4z" style="opacity:.05"\/> | |
<path d="m1 43v0.25c0 2.216 1.784 4 4 4h38c2.216 0 4-1.784 4-4v-0.25c0 2.216-1.784 4-4 4h-38c-2.216 0-4-1.784-4-4z" style="opacity:.1"\/> | |
<\/g>/ <path d="m1 43v0.25c0 2.216 1.784 4 4 4h38c2.216 0 4-1.784 4-4v-0.25c0 2.216-1.784 4-4 4h-38c-2.216 0-4-1.784-4-4zm0 0.5v0.5c0 2.216 1.784 4 4 4h38c2.216 0 4-1.784 4-4v-0.5c0 2.216-1.784 4-4 4h-38c-2.216 0-4-1.784-4-4z" style="opacity:.02"\/> | |
<path d="m1 43.25v0.25c0 2.216 1.784 4 4 4h38c2.216 0 4-1.784 4-4v-0.25c0 2.216-1.784 4-4 4h-38c-2.216 0-4-1.784-4-4z" style="opacity:.05"\/> | |
<path d="m1 43v0.25c0 2.216 1.784 4 4 4h38c2.216 0 4-1.784 4-4v-0.25c0 2.216-1.784 4-4 4h-38c-2.216 0-4-1.784-4-4z" style="opacity:.1"\/>/s' "${1}" | |
perl -i -p0e 's/ <g transform="translate\(0 3.949e-5\)"> | |
<g transform="translate\(0 -1004.4\)"> | |
<path d="m1 1043.4v4c0 2.216 1.784 4 4 4h38c2.216 0 4-1.784 4-4v-4c0 2.216-1.784 4-4 4h-38c-2.216 0-4-1.784-4-4z" style="opacity:.1"\/> | |
<\/g> | |
<\/g>/ <path d="m1 39v4c0 2.216 1.784 4 4 4h38c2.216 0 4-1.784 4-4v-4c0 2.216-1.784 4-4 4h-38c-2.216 0-4-1.784-4-4z" style="opacity:.1"\/>/s' "${1}" | |
sed -e "s/GRADIENT_TEMPORARY/linearGradient${__gradient_number}/" -i "${1}" | |
echo "${1}" | |
} | |
all_circle () { | |
find icons/circle/48/ -type f | sort | while read -r __file; do | |
replace_baseplate_circle "${__file}" & | |
done | |
} | |
all_square () { | |
find icons/square/48/ -type f | sort | while read -r __file; do | |
replace_baseplate_square "${__file}" & | |
done | |
} | |
if [ "${#}" = '0' ]; then | |
all_circle | |
all_square | |
wait | |
else | |
until [ "${#}" = '0' ]; do | |
if [ -e "icons/circle/48/${1}.svg" ]; then | |
replace_baseplate_circle "icons/circle/48/${1}.svg" | |
fi | |
if [ -e "icons/square/48/${1}.svg" ]; then | |
replace_baseplate_square "icons/square/48/${1}.svg" | |
fi | |
shift | |
done | |
fi | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment