forked from ryanoasis/nerd-fonts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gotta-patch-em-all-font-patcher!.sh
executable file
·153 lines (122 loc) · 5.5 KB
/
gotta-patch-em-all-font-patcher!.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/bin/bash
# version: 0.8.0
# Check for Fontforge
type fontforge >/dev/null 2>&1 || {
echo >&2 "FontForge must be installed before running this script."
echo >&2 "Please see installation instructions at"
echo >&2 "http://designwithfontforge.com/en-US/Installing_Fontforge.html"
exit 1
}
res1=$(date +%s)
# Set source and target directories
source_fonts_dir="${PWD}/unpatched-sample-fonts"
patched_fonts_dir="${PWD}/patched-fonts"
like_pattern=''
organizing_sub_dir=""
if [ $# -eq 1 ]
then
like_pattern=$1
echo "Parameter given, limiting search and patch to pattern '$like_pattern' given"
fi
# correct way to output find results into an array (when files have space chars, etc)
# source: http://stackoverflow.com/questions/8213328/bash-script-find-output-to-array
source_fonts=()
while IFS= read -d $'\0' -r file ; do
source_fonts=("${source_fonts[@]}" "$file")
done < <(find "$source_fonts_dir" -name "$like_pattern*.[o,t]tf" -type f -print0)
# print total number of source fonts found
echo "Total source fonts found: ${#source_fonts[*]}"
function patch_font {
local f=$1; shift
local organizing_sub_dir=$1; shift
# take everything before the last slash (/) to start building the full path
local patched_font_dir="${f%/*}/"
printf "\n---------------\n"
local patched_font_dir="${patched_font_dir/unpatched-sample-fonts/patched-fonts}"
echo "patched font dir is $patched_font_dir"
local patched_font_dir+=$organizing_sub_dir
echo "patched font dir is $patched_font_dir"
[[ -d "$patched_font_dir" ]] || mkdir -p "$patched_font_dir"
fontforge -quiet -script ./font-patcher "$@" "$f" --outputdir $patched_font_dir 2>/dev/null
}
function patch_font_batch {
patch_font "$@" -q
patch_font "$@" -q -s
patch_font "$@" -q -w
patch_font "$@" -q -s -w
}
# Use for loop iterate through source fonts
# $f stores current value
for f in "${source_fonts[@]}"
do
echo "$f"
config_parent_dir=$( cd "$( dirname "$f" )" && cd ".." && pwd)
config_dir=$( cd "$( dirname "$f" )" && pwd)
# source the font config file if exists:
if [ -f "$config_dir/config.cfg" ]
then
source "$config_dir/config.cfg"
elif [ -f "$config_parent_dir/config.cfg" ]
then
source "$config_parent_dir/config.cfg"
fi
if [ $config_has_powerline ]
then
powerline=""
else
powerline="--powerline"
fi
patch_font_batch "$f" "minimal/" $powerline &
# font awesome variations
patch_font_batch "$f" "additional-variations/" $powerline --fontawesome &
patch_font_batch "$f" "additional-variations/" $powerline --fontawesome --powerlineextra &
# octicons variations:
patch_font_batch "$f" "additional-variations/" $powerline --octicons &
patch_font_batch "$f" "additional-variations/" $powerline --octicons --powerlineextra &
# font linux variations:
patch_font_batch "$f" "additional-variations/" $powerline --fontlinux &
patch_font_batch "$f" "additional-variations/" $powerline --fontlinux --powerlineextra &
# pomicon variations:
patch_font_batch "$f" "additional-variations/" $powerline --pomicons &
patch_font_batch "$f" "additional-variations/" $powerline --pomicons --powerlineextra &
# fontawesome + octicons variations:
patch_font_batch "$f" "additional-variations/" $powerline --fontawesome --octicons &
patch_font_batch "$f" "additional-variations/" $powerline --fontawesome --octicons --powerlineextra &
# fontawesome + pomicons variations:
patch_font_batch "$f" "additional-variations/" $powerline --fontawesome --pomicons &
patch_font_batch "$f" "additional-variations/" $powerline --fontawesome --pomicons --powerlineextra &
# fontawesome + fontlinux variations:
patch_font_batch "$f" "additional-variations/" $powerline --fontawesome --fontlinux &
patch_font_batch "$f" "additional-variations/" $powerline --fontawesome --fontlinux --powerlineextra &
# fontlinux + pomicons variations:
patch_font_batch "$f" "additional-variations/" $powerline --fontlinux --pomicons &
patch_font_batch "$f" "additional-variations/" $powerline --fontlinux --pomicons --powerlineextra &
# octicons + pomicons variations:
patch_font_batch "$f" "additional-variations/" $powerline --octicons --pomicons &
patch_font_batch "$f" "additional-variations/" $powerline --octicons --pomicons --powerlineextra &
# octicons + fontlinux variations:
patch_font_batch "$f" "additional-variations/" $powerline --octicons --fontlinux &
patch_font_batch "$f" "additional-variations/" $powerline --octicons --fontlinux --powerlineextra &
# fontawesome + octicons + pomicons variations:
patch_font_batch "$f" "additional-variations/" $powerline --fontawesome --octicons --pomicons &
# fontawesome + octicons + pomicons + fontlinux variations:
patch_font_batch "$f" "additional-variations/" $powerline --fontawesome --octicons --pomicons --fontlinux &
# fontawesome + octicons + pomicons + powerlineextra variations (aka Complete):
patch_font_batch "$f" "complete/" $powerline --fontawesome --octicons --pomicons --powerlineextra --fontlinux &
# un-comment to test this script (patch 1 font)
#break
# wait for this set of bg commands to finish: dont do too many at once!
wait
done
# wait for all bg commands to finish
wait
res2=$(date +%s)
dt=$(echo "$res2 - $res1" | bc)
dd=$(echo "$dt/86400" | bc)
dt2=$(echo "$dt-86400*$dd" | bc)
dh=$(echo "$dt2/3600" | bc)
dt3=$(echo "$dt2-3600*$dh" | bc)
dm=$(echo "$dt3/60" | bc)
ds=$(echo "$dt3-60*$dm" | bc)
printf "Total runtime: %d:%02d:%02d:%02d\n" $dd $dh $dm $ds
echo "All unpatched fonts re-patched to their respective sub-directories in $patched_fonts_dir"