papirus-icon-theme/tools/ffsvg.sh

81 lines
1.8 KiB
Bash
Raw Normal View History

#!/bin/sh
#
# Written in 2016 by Sergei Eremenko <https://github.com/SmartFinn>
#
# 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 finds, fixes and cleans SVG files.
#
# Usage:
# ffsvg.sh PATH...
2016-12-18 02:53:22 -05:00
set -e
SCRIPT_DIR="$(dirname "$0")"
_run_helpers() {
2019-11-19 06:34:03 -05:00
echo "=> Working on '$1' ..."
# optimize a SVG
2017-05-13 13:39:55 -04:00
if command -v svgo > /dev/null 2>&1; then
# use SVGO
svgo --config="$SCRIPT_DIR/svgo.config.js" -i "$1" -o "$1".tmp
mv -f "$1".tmp "$1"
2017-05-13 13:39:55 -04:00
elif command -v scour > /dev/null 2>&1; then
# use scour
"$SCRIPT_DIR/_scour.sh" "$1"
2017-05-13 13:39:55 -04:00
else
2019-11-19 06:34:03 -05:00
cat >&2 <<-'EOF'
2017-05-13 13:39:55 -04:00
2018-09-03 02:37:39 -04:00
You have to install svgo or scour to use this script:
2017-05-13 13:39:55 -04:00
2018-09-03 02:37:39 -04:00
sudo npm install -g svgo
2017-05-13 13:39:55 -04:00
sudo apt-get install python-scour
EOF
exit 1
fi
# fix a color scheme
"$SCRIPT_DIR/_fix_color_scheme.sh" "$1"
2017-03-26 15:21:12 -04:00
# clear attributes
2017-05-13 13:39:55 -04:00
sed -r -i -f "$SCRIPT_DIR/_clean_attrs.sed" "$1"
2017-03-26 15:21:12 -04:00
# clear a style attribute
2017-05-13 13:39:55 -04:00
sed -r -i -f "$SCRIPT_DIR/_clean_style_attr.sed" "$1"
}
for i in "$@"; do
if [ -d "$i" ]; then
2019-11-19 06:34:03 -05:00
# it's a directory
2019-11-19 06:34:03 -05:00
echo "=> Directory '$i' will be processed."
echo " Press <CTRL-C> to abort (wait 1 seconds) ..."
2017-07-21 04:18:47 -04:00
sleep 1
# process all SVG files w/o symlinks
2017-09-27 13:04:07 -04:00
find "$i" -type f -name '*.svg' | while read -r file; do
_run_helpers "$file"
done
elif [ -f "$i" ] && [ ! -L "$i" ]; then
2019-11-19 06:34:03 -05:00
# it's a file and not a symlink
# continue if an extension is svg
[ "${i##*.}" = "svg" ] || continue
_run_helpers "$i"
else
continue
fi
done