-
-
Notifications
You must be signed in to change notification settings - Fork 185
/
iconset
executable file
·128 lines (101 loc) · 3.3 KB
/
iconset
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/env bash
set -e
tmp_dir=$(mktemp -d)
icons_data_file="Library/Icons.rb"
icons_dir="icons"
original_dir="icons/original"
preview_dir="icons/preview"
workflows_dir=".github/workflows"
count_total=0
count_step=0
function check() {
command -v "$1" >/dev/null 2>&1
}
check convert || {
echo "You need to install 'convert' tool as part of 'imagemagick'"
exit 1
}
check png2icns || {
echo "You need to install 'png2icns' tool as part of 'libicns'"
exit 1
}
check sha256sum || {
echo "You need to install 'sha256sum' tool"
exit 1
}
function process() {
local name="${1%.png}"
local size="${#count_total}"
local sha256=
local icns_file="$icons_dir/${name}.icns"
local workflow="${workflows_dir}/icon-${name}.yml"
count_step=$((count_step+1))
printf "[%${size}d/%d] %s\n" $count_step $count_total "$name"
cp "${original_dir}/${name}.png" "${tmp_dir}/${name}.png"
(
cd "$tmp_dir"
convert "${name}.png" -resize 1024x1024! "${name}_1024.png"
convert "${name}.png" -resize 512x512! "${name}_512.png"
# convert "${name}.png" -resize 512x512! "${name}[email protected]"
convert "${name}.png" -resize 256x256! "${name}_256.png"
# convert "${name}.png" -resize 256x256! "${name}[email protected]"
convert "${name}.png" -resize 128x128! "${name}_128.png"
# convert "${name}.png" -resize 64x64! "${name}[email protected]"
convert "${name}.png" -resize 32x32! "${name}_32.png"
# convert "${name}.png" -resize 32x32! "${name}[email protected]"
convert "${name}.png" -resize 16x16! "${name}_16.png"
png2icns "${name}.icns" "${name}_1024.png" "${name}_512.png" "${name}_256.png" "${name}_128.png" "${name}_32.png" "${name}_16.png"
)
cp "${tmp_dir}/${name}.icns" "$icns_file"
# since png contains time-related metadata and we want to avoid
# dummy changes, let's copy preview ONLY when icns file changes
if ! git diff --exit-code "$icns_file" >/dev/null ||
! git ls-files --error-unmatch "$icns_file" 2>/dev/null; then
cp "${tmp_dir}/${name}_128.png" "$preview_dir/${name}_128.png"
fi
sha256=$(sha256sum "$icons_dir/${name}.icns" | cut -f 1 -d " ")
echo " \"$name\" => \"$sha256\"," >> "$icons_data_file"
cat <<EOT > "$workflow"
# This file is automatically generated by iconset script.
#
# DO NOT MODIFY it manually.
name: Icon $name
on:
push:
branches:
- master
paths:
- "$icons_dir/${name}.icns"
- "$workflow"
pull_request:
paths:
- "$icons_dir/${name}.icns"
- "$workflow"
jobs:
build:
runs-on: macos-12
env:
HOMEBREW_GITHUB_REF: \${{ github.head_ref || github.ref }}
HOMEBREW_GITHUB_REPOSITORY: \${{ github.repository }}
HOMEBREW_GITHUB_ACTOR: \${{ github.actor }}
steps:
- uses: actions/checkout@v4
- name: Build emacs-plus with $name icon
run: brew install Aliases/\$(readlink Aliases/emacs-plus) --with-$name-icon
- name: Test installation
run: \$(brew --prefix)/bin/emacs --batch --eval='(print (+ 2 2))'
EOT
}
for f in "$original_dir"/*.png; do
count_total=$((count_total+1))
done
for f in "${workflows_dir}"/icon-*.yml; do
rm "$f"
done
rm "$icons_data_file"
echo "ICONS_CONFIG = {" >> "$icons_data_file"
for f in "$original_dir"/*.png; do
process "${f#"$original_dir"/}"
done
echo "}.freeze" >> "$icons_data_file"
echo "-> done."