papirus-icon-theme/tools/_fix_color_scheme.sh

61 lines
1.7 KiB
Bash
Raw Normal View History

2016-12-05 16:33:56 -05:00
#!/bin/sh
#
2016-12-07 16:59:47 -05:00
# This script looks in the SVG files for certain colors and replaces
# them with the corresponding stylesheet class. And fixes the color
# scheme after Inkscape.
2016-12-05 16:33:56 -05:00
#
# limitations:
2016-12-07 11:48:00 -05:00
# - works only with one element per line
2016-12-05 16:33:56 -05:00
#
# usage:
# _fix_color_scheme.sh FILE...
set -e
2016-12-07 11:48:00 -05:00
add_class() {
# add the class if a value matches:
sed -i -r \
2016-12-09 12:41:21 -05:00
-e '/([^-]color|fill|stop-color):#5c616c/I s/(style="\S+")/\1 class="ColorScheme-Text"/' \
-e '/([^-]color|fill|stop-color):#5294e2/I s/(style="\S+")/\1 class="ColorScheme-Highlight"/' \
-e '/([^-]color|fill|stop-color):#d3dae3/I s/(style="\S+")/\1 class="ColorScheme-ButtonBackground"/' \
2016-12-07 11:48:00 -05:00
"$@"
}
add_class_dark() {
# add the class if a value matches:
sed -i -r \
2016-12-09 12:41:21 -05:00
-e '/([^-]color|fill|stop-color):#d3dae3/I s/(style="\S+")/\1 class="ColorScheme-Text"/' \
-e '/([^-]color|fill|stop-color):#5294e2/I s/(style="\S+")/\1 class="ColorScheme-Highlight"/' \
2016-12-07 11:48:00 -05:00
"$@"
}
fix_color_and_fill() {
# if class exist:
# - remove color
# - replace fill=#HEXHEX to fill=currentColor
sed -i -r \
-e '/class="ColorScheme-/ s/[^-]color:#([0-9a-zA-Z]{3}|[0-9a-zA-Z]{6});?//' \
2016-12-07 11:48:00 -05:00
-e '/class="ColorScheme-/ s/fill:#([0-9a-zA-Z]{3}|[0-9a-zA-Z]{6});?/fill:currentColor;/' \
-e '/class="ColorScheme-/ s/stop-color:#([0-9a-zA-Z]{3}|[0-9a-zA-Z]{6});?/stop-color:currentColor;/' \
2016-12-07 11:48:00 -05:00
"$@"
}
2016-12-05 16:33:56 -05:00
for file in "$@"; do
[ -f "$file" ] || continue
2016-12-07 11:48:00 -05:00
# skip if a file not have color scheme
2016-12-09 12:41:21 -05:00
grep -q -i '\.ColorScheme-Text' "$file" || continue
2016-12-07 11:48:00 -05:00
fix_color_and_fill "$file"
2016-12-09 12:41:21 -05:00
if grep -q -i '#5c616c' "$file"; then
2016-12-07 11:48:00 -05:00
# is Papirus
add_class "$file"
fix_color_and_fill "$file"
else
# is Papirus-Dark
add_class_dark "$file"
fix_color_and_fill "$file"
fi
2016-12-05 16:33:56 -05:00
done