mirror of
https://github.com/CyC2018/Interview-Notebook.git
synced 2026-10-27 13:33:43 +00:00
启用 git config core.hooksPath tools/hooks 后,提交时自动给 notes/pics 下新增或修改的 PNG、JPEG 图片加水印。
15 lines
640 B
Bash
Executable File
15 lines
640 B
Bash
Executable File
#!/bin/sh
|
|
# 提交时给 notes/pics 下新增或修改的 PNG、JPEG 配图自动加 CyC2018 浅水印。
|
|
# 启用:git config core.hooksPath tools/hooks
|
|
root=$(git rev-parse --show-toplevel) || exit 1
|
|
files=$(git diff --cached --name-only --diff-filter=AM -- 'notes/pics/*.png' 'notes/pics/*.jpg' 'notes/pics/*.jpeg')
|
|
[ -z "$files" ] && exit 0
|
|
if ! python3 -c "import PIL" 2>/dev/null; then
|
|
echo "pre-commit: 需要 Pillow 才能给配图加水印,请先执行 pip3 install pillow" >&2
|
|
exit 1
|
|
fi
|
|
echo "$files" | while IFS= read -r f; do
|
|
python3 "$root/tools/watermark.py" "$root/$f" || exit 1
|
|
git add -- "$root/$f"
|
|
done
|