-
Notifications
You must be signed in to change notification settings - Fork 13
/
make_gallery.sh
executable file
·45 lines (35 loc) · 1.05 KB
/
make_gallery.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env bash
set -e
# Usage: ./make_gallery.sh
#
# Run in a directory with a "papes/" subdirectory, and it will create a
# "thumbnails/" subdirectory.
#
# Uses imagemagick's `convert`, so make sure that's installed.
# On Nix, nix-shell -p imagemagick --run ./make_gallery.sh
mv thumbnails thumbnails_old
mkdir thumbnails
echo "### Wallpapers" >README.md
echo "My current wallpaper rotation" >>README.md
echo "" >>README.md
total=$(git ls-files papes/ | wc -l)
i=0
git ls-files papes/ -z | while read -d $'\0' src; do
((i++)) || true
filename="$(basename "$src")"
printf '%4d/%d: %s... ' "$i" "$total" "$filename"
target="${src/papes/thumbnails}"
thumbnail_old="${src/papes/thumbnails_old}"
if [[ ! -f "$thumbnail_old" ]]; then
convert -resize 200x "$src" "$target"
echo "converted!"
else
mv "$thumbnail_old" "$target"
echo "skipped!"
fi
filename_escaped="${filename// /%20}"
thumb_url="thumbnails/$filename_escaped"
pape_url="papes/$filename_escaped"
echo "[![$filename]($thumb_url)]($pape_url)" >>README.md
done
rm -rf thumbnails_old