papirus-icon-theme/tools/_fix_color_scheme.sh

90 lines
2.9 KiB
Bash
Raw Normal View History

2016-12-05 16:33:56 -05:00
#!/bin/sh
#
# Written in 2016 by Sergei Eremenko <https://github.com/SmartFinn>
2016-12-05 16:33:56 -05:00
#
# To the extent possible under law, the author(s) have dedicated all copyright
# and related and neighboring rights to this software to the public domain
# worldwide. This software is distributed without any warranty.
#
# You should have received a copy of the CC0 Public Domain Dedication along
# with this software. If not, see
# <http://creativecommons.org/publicdomain/zero/1.0/>.
#
# Description:
# This script looks in the SVG files for certain colors and replaces
# them with the corresponding stylesheet class. Fixes a color scheme
# after Inkscape.
#
# 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...
2016-12-05 16:33:56 -05:00
set -e
2017-02-19 08:53:00 -05:00
# Papirus and Papirus-Light
2016-12-07 11:48:00 -05:00
add_class() {
# add the class if a value matches:
sed -i -r \
-e '/([^-]color|fill|stop-color|stroke):#5c616c/I s/(style="\S+")/\1 class="ColorScheme-Text"/' \
-e '/([^-]color|fill|stop-color|stroke):#5294e2/I s/(style="\S+")/\1 class="ColorScheme-Highlight"/' \
-e '/([^-]color|fill|stop-color|stroke):#d3dae3/I s/(style="\S+")/\1 class="ColorScheme-ButtonBackground"/' \
2016-12-07 11:48:00 -05:00
"$@"
}
2017-02-19 08:53:00 -05:00
# Papirus-Dark
2016-12-07 11:48:00 -05:00
add_class_dark() {
# add the class if a value matches:
sed -i -r \
-e '/([^-]color|fill|stop-color|stroke):#d3dae3/I s/(style="\S+")/\1 class="ColorScheme-Text"/' \
-e '/([^-]color|fill|stop-color|stroke):#5294e2/I s/(style="\S+")/\1 class="ColorScheme-Highlight"/' \
2016-12-07 11:48:00 -05:00
"$@"
}
2017-02-19 08:53:00 -05:00
# ePapirus
add_class_e() {
# add the class if a value matches:
sed -i -r \
-e '/([^-]color|fill|stop-color|stroke):#6e6e6e/I s/(style="\S+")/\1 class="ColorScheme-Text"/' \
-e '/([^-]color|fill|stop-color|stroke):#5294e2/I s/(style="\S+")/\1 class="ColorScheme-Highlight"/' \
-e '/([^-]color|fill|stop-color|stroke):#ffffff/I s/(style="\S+")/\1 class="ColorScheme-ButtonBackground"/' \
"$@"
}
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 \
2016-12-10 19:17:38 -05:00
-e '/class="ColorScheme-/ s/([^-])color:#([[:xdigit:]]{3}|[[:xdigit:]]{6});?/\1/' \
-e '/class="ColorScheme-/ s/fill:#([[:xdigit:]]{3}|[[:xdigit:]]{6});?/fill:currentColor;/' \
-e '/class="ColorScheme-/ s/stroke:#([[:xdigit:]]{3}|[[:xdigit:]]{6});?/stroke:currentColor;/' \
2016-12-10 19:17:38 -05:00
-e '/class="ColorScheme-/ s/stop-color:#([[:xdigit:]]{3}|[[:xdigit:]]{6});?/stop-color:currentColor;/' \
2016-12-07 11:48:00 -05:00
"$@"
}
2016-12-05 16:33:56 -05:00
for file in "$@"; do
# continue if it is a file
2016-12-05 16:33:56 -05:00
[ -f "$file" ] || continue
# continue if the file has a 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
2017-02-19 08:53:00 -05:00
# it is Papirus or Papirus-Light
2016-12-07 11:48:00 -05:00
add_class "$file"
fix_color_and_fill "$file"
2017-02-19 08:53:00 -05:00
elif grep -q -i '#6e6e6e' "$file"; then
# it is ePapirus
add_class_e "$file"
fix_color_and_fill "$file"
2016-12-07 11:48:00 -05:00
else
2017-02-19 08:53:00 -05:00
# it is Papirus-Dark
2016-12-07 11:48:00 -05:00
add_class_dark "$file"
fix_color_and_fill "$file"
fi
2016-12-05 16:33:56 -05:00
done