-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
generate-casks.sh
executable file
·129 lines (100 loc) · 3.51 KB
/
generate-casks.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
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
#!/bin/bash
# version: 1.0.0
# Iterates over all patched fonts directories
# to generate ruby cask files for homebrew-fonts (https://github.com/caskroom/homebrew-fonts)
# only adds non-Windows versions of the fonts
#set -x
version="1.0.0"
patched_parent_dir="../../patched-fonts/"
homepage="https://github.com/ryanoasis/nerd-fonts"
downloadarchive="https://github.com/ryanoasis/nerd-fonts/releases/download/v#{version}/"
sha256sum=":no_check"
appcast="https://github.com/ryanoasis/nerd-fonts/releases.atom"
appcastcheckpoint=$(curl --compressed --location --user-agent 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36' "https://github.com/ryanoasis/nerd-fonts/releases.atom" | sed 's|<pubDate>[^<]*</pubDate>||g' | shasum --algorithm 256 | head -c 64)
cd $patched_parent_dir || {
echo >&2 "# Could not find patched fonts directory"
exit 1
}
function clear_file {
local outputfile=$1
# clear output file (needed for multiple runs or updates):
> "$outputfile" 2> /dev/null
}
function write_header {
local outputfile=$1
local caskname=$2
{
printf "cask '%s' do\n" "$caskname"
printf " version '%s'\n" "$version"
printf " sha256 '%s'\n\n" "$sha256sum"
printf " url \"%s%s.zip\"\n" "$downloadarchive" "$basename"
printf " appcast '%s',\n" "$appcast"
printf " checkpoint: '%s'\n" "$appcastcheckpoint"
} >> "$outputfile"
}
function write_body {
local outputfile=$1
shift;
local fonts=("$@")
if [ "${fonts[0]}" ];
then
for i in "${!fonts[@]}"
do
individualfont=$(basename "${fonts[$i]}")
printf "## Found Font: %s\n" "${fonts[$i]}"
if [ "$i" == 0 ];
then
familyname=$(fc-query --format='%{family}' "${fonts[$i]}")
{
printf " name '%s (%s)'\n" "$familyname" "$basename"
printf " homepage '%s'" "$homepage"
printf "\n\n"
} >> "$outputfile"
fi
printf " font '%s'\n" "$individualfont" >> "$outputfile"
done
else
echo "# Did not find TTF or OTF"
fi
}
function write_footer {
local outputfile=$1
{
printf "end\n"
} >> "$outputfile"
}
#find ./Hack -maxdepth 0 -type d | # uncomment to test 1 font
#find ./ProFont -maxdepth 2 -type d | # uncomment to test 1 font
find . -maxdepth 1 -type d | # uncomment to test 1 font
while read -r filename
do
dirname=$(dirname "$filename")
basename=$(basename "$filename")
sha256sum=$(sha256sum "../archives/${basename}.zip" | head -c 64)
searchdir=$filename
fontdir=$(basename "$(dirname "$dirname")")
MONOFONTS=()
while IFS= read -d $'\0' -r file ; do
MONOFONTS=("${MONOFONTS[@]}" "$file")
done < <(find "$searchdir" -type f -iwholename '*complete*' \( -iname '*.[o,t]tf' ! -wholename '*Windows*' -iname '*mono.*' \) -print0)
FONTS=()
while IFS= read -d $'\0' -r file ; do
FONTS=("${FONTS[@]}" "$file")
done < <(find "$searchdir" -type f -iwholename '*complete*' \( -iname '*.[o,t]tf' ! -wholename '*Windows*' ! -iwholename '*mono.*' \) -print0)
outputdir=$PWD/../casks/
formattedbasename=$(echo "$basename" | tr "[:upper:]" "[:lower:]")
echo "# Generating cask for: $fontdir"
[[ -d "$outputdir" ]] || mkdir -p "$outputdir"
caskname="font-$formattedbasename-nerd-font"
caskname_mono="${caskname}-mono"
to="$outputdir/${caskname}.rb"
to_mono="$outputdir/${caskname_mono}.rb"
clear_file "$to"
write_header "$to" "$caskname"
clear_file "$to_mono"
write_header "$to_mono" "$caskname_mono"
write_body "$to" "${FONTS[@]}"
write_body "$to_mono" "${MONOFONTS[@]}"
write_footer "$to"
write_footer "$to_mono"
done