Created
December 21, 2017 14:09
-
-
Save W-Floyd/d989f88105d85d191554447b15939995 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 | |
ask() { | |
# https://djm.me/ask | |
local prompt default reply | |
while true; do | |
if [ "${2:-}" = "Y" ]; then | |
prompt="Y/n" | |
default=Y | |
elif [ "${2:-}" = "N" ]; then | |
prompt="y/N" | |
default=N | |
else | |
prompt="y/n" | |
default= | |
fi | |
# Ask the question (not using "read -p" as it uses stderr not stdout) | |
echo -n "$1 [$prompt] " | |
# Read the answer (use /dev/tty in case stdin is redirected from somewhere else) | |
read reply </dev/tty | |
# Default? | |
if [ -z "$reply" ]; then | |
reply=$default | |
fi | |
# Check if the reply is valid | |
case "$reply" in | |
Y*|y*) return 0 ;; | |
N*|n*) return 1 ;; | |
esac | |
done | |
} | |
if ! [ -e './replace_baseplate.sh' ]; then | |
echo 'You need replace_baseplate.sh present.' | |
exit 1 | |
fi | |
while read -r __name; do | |
if ! which "${__name}" &> /dev/null; then | |
echo "You need ${__name} installed" | |
exit 1 | |
fi | |
done <<< 'parallel | |
rsvg-convert | |
composite' | |
if ! ask "This will discard any changes to icon and create some file, continue?"; then | |
echo 'Okay.' | |
exit 1 | |
fi | |
git discard icons | |
mkdir -p ignore/visualdiff/original/circle | |
mkdir -p ignore/visualdiff/original/square | |
process_image () { | |
__file="${!#}" | |
__name="$(sed -e 's/^.*\/\(.*\).svg$/\1/' <<< "${__file}")" | |
__output="ignore/visualdiff/${1}/${2}/${__name}.png" | |
if ! [ -e "${__output}" ]; then | |
echo "${__name}" | |
rsvg-convert "${__file}" --zoom=2 -o "${__output}" | |
fi | |
} | |
process_new () { | |
process_image new "${@}" | |
} | |
process_original () { | |
process_image original "${@}" | |
} | |
compare_image () { | |
__file="${!#}" | |
__name="$(sed -e 's/^.*\///' <<< "${__file}")" | |
composite "ignore/visualdiff/new/${1}/${__name}" "ignore/visualdiff/original/${1}/${__name}" -compose difference "ignore/visualdiff/compare/${1}/${__name}" | |
} | |
export -f process_image process_new process_original compare_image | |
while read -r __theme; do | |
find "icons/${__theme}/48/" -type f | sort | parallel -j10 process_original "${__theme}" | |
done <<< 'circle | |
square' | |
./replace_baseplate.sh | |
mkdir -p ignore/visualdiff/new/circle | |
mkdir -p ignore/visualdiff/new/square | |
while read -r __theme; do | |
git diff --name-only "icons/${__theme}/48/" | sort | parallel -j10 process_new "${__theme}" | |
done <<< 'circle | |
square' | |
mkdir -p ignore/visualdiff/compare/circle | |
mkdir -p ignore/visualdiff/compare/square | |
while read -r __theme; do | |
find "ignore/visualdiff/new/${__theme}/" -type f | sort | parallel -j10 compare_image "${__theme}" | |
done <<< 'circle | |
square' | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment