2015-08-11 00:33:21 +02:00
|
|
|
#!/bin/bash
|
2016-05-08 23:04:21 +02:00
|
|
|
# version: 0.8.0
|
2015-08-11 00:33:21 +02:00
|
|
|
|
2015-09-02 22:14:55 +02:00
|
|
|
# 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
|
|
|
|
}
|
2015-08-11 00:33:21 +02:00
|
|
|
|
2015-11-16 01:05:57 +02:00
|
|
|
res1=$(date +%s)
|
|
|
|
|
2015-08-11 00:33:21 +02:00
|
|
|
# Set source and target directories
|
|
|
|
source_fonts_dir="${PWD}/unpatched-sample-fonts"
|
|
|
|
patched_fonts_dir="${PWD}/patched-fonts"
|
|
|
|
like_pattern=''
|
2015-11-14 23:49:18 +02:00
|
|
|
organizing_sub_dir=""
|
2015-08-11 00:33:21 +02:00
|
|
|
|
|
|
|
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")
|
2015-09-02 22:14:55 +02:00
|
|
|
done < <(find "$source_fonts_dir" -name "$like_pattern*.[o,t]tf" -type f -print0)
|
2015-08-11 00:33:21 +02:00
|
|
|
|
|
|
|
# print total number of source fonts found
|
|
|
|
echo "Total source fonts found: ${#source_fonts[*]}"
|
|
|
|
|
|
|
|
|
2015-09-02 22:14:55 +02:00
|
|
|
function patch_font {
|
|
|
|
local f=$1; shift
|
2015-11-16 01:05:57 +02:00
|
|
|
local organizing_sub_dir=$1; shift
|
|
|
|
# take everything before the last slash (/) to start building the full path
|
2015-09-02 22:14:55 +02:00
|
|
|
local patched_font_dir="${f%/*}/"
|
2015-11-16 01:05:57 +02:00
|
|
|
printf "\n---------------\n"
|
2015-09-02 22:14:55 +02:00
|
|
|
local patched_font_dir="${patched_font_dir/unpatched-sample-fonts/patched-fonts}"
|
2015-11-14 23:49:18 +02:00
|
|
|
echo "patched font dir is $patched_font_dir"
|
|
|
|
local patched_font_dir+=$organizing_sub_dir
|
|
|
|
echo "patched font dir is $patched_font_dir"
|
2015-09-02 22:14:55 +02:00
|
|
|
[[ -d "$patched_font_dir" ]] || mkdir -p "$patched_font_dir"
|
2015-11-16 01:05:57 +02:00
|
|
|
fontforge -quiet -script ./font-patcher "$@" "$f" --outputdir $patched_font_dir 2>/dev/null
|
2015-09-02 22:14:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function patch_font_batch {
|
|
|
|
patch_font "$@" -q
|
|
|
|
patch_font "$@" -q -s
|
|
|
|
patch_font "$@" -q -w
|
|
|
|
patch_font "$@" -q -s -w
|
|
|
|
}
|
2015-08-11 00:33:21 +02:00
|
|
|
|
|
|
|
# Use for loop iterate through source fonts
|
|
|
|
# $f stores current value
|
|
|
|
for f in "${source_fonts[@]}"
|
|
|
|
do
|
2015-09-02 22:21:13 +02:00
|
|
|
echo "$f"
|
2016-05-08 18:22:15 +02:00
|
|
|
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 ]
|
2015-09-02 22:21:13 +02:00
|
|
|
then
|
|
|
|
powerline=""
|
|
|
|
else
|
|
|
|
powerline="--powerline"
|
|
|
|
fi
|
|
|
|
|
2015-11-16 01:05:57 +02:00
|
|
|
patch_font_batch "$f" "minimal/" $powerline &
|
2015-11-14 23:49:18 +02:00
|
|
|
|
2015-09-02 22:14:55 +02:00
|
|
|
# font awesome variations
|
2015-11-16 01:05:57 +02:00
|
|
|
patch_font_batch "$f" "additional-variations/" $powerline --fontawesome &
|
|
|
|
patch_font_batch "$f" "additional-variations/" $powerline --fontawesome --powerlineextra &
|
2015-08-11 00:33:21 +02:00
|
|
|
|
2015-09-02 22:14:55 +02:00
|
|
|
# octicons variations:
|
2015-11-16 01:05:57 +02:00
|
|
|
patch_font_batch "$f" "additional-variations/" $powerline --octicons &
|
|
|
|
patch_font_batch "$f" "additional-variations/" $powerline --octicons --powerlineextra &
|
2015-08-11 00:33:21 +02:00
|
|
|
|
2016-05-08 22:58:54 +02:00
|
|
|
# font linux variations:
|
|
|
|
patch_font_batch "$f" "additional-variations/" $powerline --fontlinux &
|
|
|
|
patch_font_batch "$f" "additional-variations/" $powerline --fontlinux --powerlineextra &
|
|
|
|
|
2015-09-02 22:14:55 +02:00
|
|
|
# pomicon variations:
|
2015-11-16 01:05:57 +02:00
|
|
|
patch_font_batch "$f" "additional-variations/" $powerline --pomicons &
|
|
|
|
patch_font_batch "$f" "additional-variations/" $powerline --pomicons --powerlineextra &
|
2015-08-11 00:33:21 +02:00
|
|
|
|
2015-09-02 22:14:55 +02:00
|
|
|
# fontawesome + octicons variations:
|
2015-11-16 01:05:57 +02:00
|
|
|
patch_font_batch "$f" "additional-variations/" $powerline --fontawesome --octicons &
|
|
|
|
patch_font_batch "$f" "additional-variations/" $powerline --fontawesome --octicons --powerlineextra &
|
2015-08-11 00:33:21 +02:00
|
|
|
|
2015-09-02 22:14:55 +02:00
|
|
|
# fontawesome + pomicons variations:
|
2015-11-16 01:05:57 +02:00
|
|
|
patch_font_batch "$f" "additional-variations/" $powerline --fontawesome --pomicons &
|
|
|
|
patch_font_batch "$f" "additional-variations/" $powerline --fontawesome --pomicons --powerlineextra &
|
2015-08-11 00:33:21 +02:00
|
|
|
|
2016-05-08 22:58:54 +02:00
|
|
|
# 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 &
|
|
|
|
|
2015-09-02 22:14:55 +02:00
|
|
|
# octicons + pomicons variations:
|
2015-11-16 01:05:57 +02:00
|
|
|
patch_font_batch "$f" "additional-variations/" $powerline --octicons --pomicons &
|
|
|
|
patch_font_batch "$f" "additional-variations/" $powerline --octicons --pomicons --powerlineextra &
|
2015-08-11 00:33:21 +02:00
|
|
|
|
2016-05-08 22:58:54 +02:00
|
|
|
# octicons + fontlinux variations:
|
|
|
|
patch_font_batch "$f" "additional-variations/" $powerline --octicons --fontlinux &
|
|
|
|
patch_font_batch "$f" "additional-variations/" $powerline --octicons --fontlinux --powerlineextra &
|
|
|
|
|
2015-09-02 22:14:55 +02:00
|
|
|
# fontawesome + octicons + pomicons variations:
|
2015-11-16 01:05:57 +02:00
|
|
|
patch_font_batch "$f" "additional-variations/" $powerline --fontawesome --octicons --pomicons &
|
2015-11-14 23:49:18 +02:00
|
|
|
|
2016-05-08 22:58:54 +02:00
|
|
|
# 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 &
|
2015-11-16 01:05:57 +02:00
|
|
|
|
2015-11-14 23:49:18 +02:00
|
|
|
|
2015-09-02 22:14:55 +02:00
|
|
|
# un-comment to test this script (patch 1 font)
|
|
|
|
#break
|
2015-11-16 01:05:57 +02:00
|
|
|
# wait for this set of bg commands to finish: dont do too many at once!
|
|
|
|
wait
|
2015-08-11 00:33:21 +02:00
|
|
|
done
|
2015-11-16 01:05:57 +02:00
|
|
|
# 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
|
2015-08-11 00:33:21 +02:00
|
|
|
|
|
|
|
echo "All unpatched fonts re-patched to their respective sub-directories in $patched_fonts_dir"
|