| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
if [ -z $1 ]; then |
| 4 |
CMD="git diff-index --raw --name-status HEAD" |
| 5 |
else |
| 6 |
CMD="git diff --raw --name-status $1^ $1" |
| 7 |
fi |
| 8 |
|
| 9 |
echo_exit() |
| 10 |
{ |
| 11 |
echo $1 |
| 12 |
exit |
| 13 |
} |
| 14 |
|
| 15 |
find_files() |
| 16 |
{ |
| 17 |
$CMD | grep '^\(A\|M\).*png$' | sed 's/^.\t//' |
| 18 |
} |
| 19 |
|
| 20 |
cd "$(git rev-parse --show-toplevel)" |
| 21 |
[ $(find_files | wc -l) != 0 ] \ |
| 22 |
|| echo_exit "No changed .png files -- please 'git add' them first." |
| 23 |
find_files | xargs -d "\n" optipng -o4 -i0 -fix |
| 24 |
find_files | xargs -d "\n" advpng -z2 |