Skip to content

Commit

Permalink
Patcher Script clean up
Browse files Browse the repository at this point in the history
* It now runs on OS X
  * find incompatibility is fixed
  * FontForge from Homebrew can be found by Python
* It checks for FontForge availability and directs to installaction
  instructions if it's not found
* It is much shorter
  • Loading branch information
pointlessone committed Sep 2, 2015
1 parent 6158e08 commit bb4064d
Showing 1 changed file with 44 additions and 284 deletions.
328 changes: 44 additions & 284 deletions gotta-patch-em-all-font-patcher!.sh
@@ -1,6 +1,14 @@
#!/bin/bash
# version: 0.4.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
}

# Set source and target directories
source_fonts_dir="${PWD}/unpatched-sample-fonts"
patched_fonts_dir="${PWD}/patched-fonts"
Expand All @@ -12,313 +20,65 @@ if [ $# -eq 1 ]
echo "Parameter given, limiting search and patch to pattern '$like_pattern' given"
fi

#find_command="`find \"$source_fonts_dir\" \( -name '*.[o,t]tf' -or -name '*.pcf.gz' \) -type f -print0`"
#find_command="find $source_fonts_dir -name '*.[o,t]tf' -type f -print0"


# Execute patcher on each unpatched font
## -0 to handle space in file name
#eval "$find_command" | xargs -0 -I % echo "%" "$patched_fonts_dir/%"
# Copy generated font to it's patched subdirectory

#IFS=$'\n'
#source_fonts=( $("`find $source_fonts_dir -name '*.[o,t]tf' -type f -print0`") )
#source_fonts=( $(find $source_fonts_dir -name '*.[o,t]tf' -type f -print0) )
#source_fonts=( $($find_command) )

# 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)
#done < <( eval($find_command) )

#echo "${source_fonts[@]}"
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[*]}"
#printf "\n"
#printf "---------------- \n"

#exit

#find_new_generated_font="find . -maxdepth 1 -name '*.[o,t]tf' -type f -print0"
function patch_font {
local f=$1; shift
fontforge -script ./font-patcher "$@" "$f"
printf "\n---------------\n"
local newly_created_font=$(find . -maxdepth 1 -name '*.[o,t]tf')
echo "newly_created_font = $newly_created_font"
local patched_font_dir="${f%/*}/"
local patched_font_dir="${patched_font_dir/unpatched-sample-fonts/patched-fonts}"
[[ -d "$patched_font_dir" ]] || mkdir -p "$patched_font_dir"
mv "$newly_created_font" "$patched_font_dir"
}

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 -n "$f "
#echo -n "./font-patcher $f "
./font-patcher -q "$f"
printf "\n---------------\n"
newly_created_font=$(find -maxdepth 1 -name '*.[o,t]tf')
echo "newly_created_font = $newly_created_font"
patched_font_dir="${f%/*}/"
patched_font_dir="${patched_font_dir/unpatched-sample-fonts/patched-fonts}"
mv "$newly_created_font" $patched_font_dir
#echo "Moved newly created font to: $patched_font_dir"

./font-patcher -q -s "$f"
printf "\n---------------\n"
newly_created_font=$(find -maxdepth 1 -name '*.[o,t]tf')
echo "newly_created_font = $newly_created_font"
patched_font_dir="${f%/*}/"
patched_font_dir="${patched_font_dir/unpatched-sample-fonts/patched-fonts}"
mv "$newly_created_font" $patched_font_dir

./font-patcher -q -w "$f"
printf "\n---------------\n"
newly_created_font=$(find -maxdepth 1 -name '*.[o,t]tf')
echo "newly_created_font = $newly_created_font"
patched_font_dir="${f%/*}/"
patched_font_dir="${patched_font_dir/unpatched-sample-fonts/patched-fonts}"
mv "$newly_created_font" $patched_font_dir

./font-patcher -q -s -w "$f"
printf "\n---------------\n"
newly_created_font=$(find -maxdepth 1 -name '*.[o,t]tf')
echo "newly_created_font = $newly_created_font"
patched_font_dir="${f%/*}/"
patched_font_dir="${patched_font_dir/unpatched-sample-fonts/patched-fonts}"
mv "$newly_created_font" $patched_font_dir

# font awesome variations
./font-patcher --fontawesome -q "$f"
printf "\n---------------\n"
newly_created_font=$(find -maxdepth 1 -name '*.[o,t]tf')
echo "newly_created_font = $newly_created_font"
patched_font_dir="${f%/*}/"
patched_font_dir="${patched_font_dir/unpatched-sample-fonts/patched-fonts}"
mv "$newly_created_font" $patched_font_dir

./font-patcher --fontawesome -q -s "$f"
printf "\n---------------\n"
newly_created_font=$(find -maxdepth 1 -name '*.[o,t]tf')
echo "newly_created_font = $newly_created_font"
patched_font_dir="${f%/*}/"
patched_font_dir="${patched_font_dir/unpatched-sample-fonts/patched-fonts}"
mv "$newly_created_font" $patched_font_dir

./font-patcher --fontawesome -q -w "$f"
printf "\n---------------\n"
newly_created_font=$(find -maxdepth 1 -name '*.[o,t]tf')
echo "newly_created_font = $newly_created_font"
patched_font_dir="${f%/*}/"
patched_font_dir="${patched_font_dir/unpatched-sample-fonts/patched-fonts}"
mv "$newly_created_font" $patched_font_dir

./font-patcher --fontawesome -q -s -w "$f"
printf "\n---------------\n"
newly_created_font=$(find -maxdepth 1 -name '*.[o,t]tf')
echo "newly_created_font = $newly_created_font"
patched_font_dir="${f%/*}/"
patched_font_dir="${patched_font_dir/unpatched-sample-fonts/patched-fonts}"
mv "$newly_created_font" $patched_font_dir

# octicons variations:
./font-patcher --octicons -q "$f"
printf "\n---------------\n"
newly_created_font=$(find -maxdepth 1 -name '*.[o,t]tf')
echo "newly_created_font = $newly_created_font"
patched_font_dir="${f%/*}/"
patched_font_dir="${patched_font_dir/unpatched-sample-fonts/patched-fonts}"
mv "$newly_created_font" $patched_font_dir

./font-patcher --octicons -q -s "$f"
printf "\n---------------\n"
newly_created_font=$(find -maxdepth 1 -name '*.[o,t]tf')
echo "newly_created_font = $newly_created_font"
patched_font_dir="${f%/*}/"
patched_font_dir="${patched_font_dir/unpatched-sample-fonts/patched-fonts}"
mv "$newly_created_font" $patched_font_dir

./font-patcher --octicons -q -w "$f"
printf "\n---------------\n"
newly_created_font=$(find -maxdepth 1 -name '*.[o,t]tf')
echo "newly_created_font = $newly_created_font"
patched_font_dir="${f%/*}/"
patched_font_dir="${patched_font_dir/unpatched-sample-fonts/patched-fonts}"
mv "$newly_created_font" $patched_font_dir

./font-patcher --octicons -q -s -w "$f"
printf "\n---------------\n"
newly_created_font=$(find -maxdepth 1 -name '*.[o,t]tf')
echo "newly_created_font = $newly_created_font"
patched_font_dir="${f%/*}/"
patched_font_dir="${patched_font_dir/unpatched-sample-fonts/patched-fonts}"
mv "$newly_created_font" $patched_font_dir

# pomicon variations:
./font-patcher --pomicons -q "$f"
printf "\n---------------\n"
newly_created_font=$(find -maxdepth 1 -name '*.[o,t]tf')
echo "newly_created_font = $newly_created_font"
patched_font_dir="${f%/*}/"
patched_font_dir="${patched_font_dir/unpatched-sample-fonts/patched-fonts}"
mv "$newly_created_font" $patched_font_dir

./font-patcher --pomicons -q -s "$f"
printf "\n---------------\n"
newly_created_font=$(find -maxdepth 1 -name '*.[o,t]tf')
echo "newly_created_font = $newly_created_font"
patched_font_dir="${f%/*}/"
patched_font_dir="${patched_font_dir/unpatched-sample-fonts/patched-fonts}"
mv "$newly_created_font" $patched_font_dir

./font-patcher --pomicons -q -w "$f"
printf "\n---------------\n"
newly_created_font=$(find -maxdepth 1 -name '*.[o,t]tf')
echo "newly_created_font = $newly_created_font"
patched_font_dir="${f%/*}/"
patched_font_dir="${patched_font_dir/unpatched-sample-fonts/patched-fonts}"
mv "$newly_created_font" $patched_font_dir

./font-patcher --pomicons -q -s -w "$f"
printf "\n---------------\n"
newly_created_font=$(find -maxdepth 1 -name '*.[o,t]tf')
echo "newly_created_font = $newly_created_font"
patched_font_dir="${f%/*}/"
patched_font_dir="${patched_font_dir/unpatched-sample-fonts/patched-fonts}"
mv "$newly_created_font" $patched_font_dir

# fontawesome + octicons variations:
./font-patcher --fontawesome --octicons -q "$f"
printf "\n---------------\n"
newly_created_font=$(find -maxdepth 1 -name '*.[o,t]tf')
echo "newly_created_font = $newly_created_font"
patched_font_dir="${f%/*}/"
patched_font_dir="${patched_font_dir/unpatched-sample-fonts/patched-fonts}"
mv "$newly_created_font" $patched_font_dir

./font-patcher --fontawesome --octicons -q -s "$f"
printf "\n---------------\n"
newly_created_font=$(find -maxdepth 1 -name '*.[o,t]tf')
echo "newly_created_font = $newly_created_font"
patched_font_dir="${f%/*}/"
patched_font_dir="${patched_font_dir/unpatched-sample-fonts/patched-fonts}"
mv "$newly_created_font" $patched_font_dir

./font-patcher --fontawesome --octicons -q -w "$f"
printf "\n---------------\n"
newly_created_font=$(find -maxdepth 1 -name '*.[o,t]tf')
echo "newly_created_font = $newly_created_font"
patched_font_dir="${f%/*}/"
patched_font_dir="${patched_font_dir/unpatched-sample-fonts/patched-fonts}"
mv "$newly_created_font" $patched_font_dir

./font-patcher --fontawesome --octicons -q -s -w "$f"
printf "\n---------------\n"
newly_created_font=$(find -maxdepth 1 -name '*.[o,t]tf')
echo "newly_created_font = $newly_created_font"
patched_font_dir="${f%/*}/"
patched_font_dir="${patched_font_dir/unpatched-sample-fonts/patched-fonts}"
mv "$newly_created_font" $patched_font_dir

# fontawesome + pomicons variations:
./font-patcher --fontawesome --pomicons -q "$f"
printf "\n---------------\n"
newly_created_font=$(find -maxdepth 1 -name '*.[o,t]tf')
echo "newly_created_font = $newly_created_font"
patched_font_dir="${f%/*}/"
patched_font_dir="${patched_font_dir/unpatched-sample-fonts/patched-fonts}"
mv "$newly_created_font" $patched_font_dir

./font-patcher --fontawesome --pomicons -q -s "$f"
printf "\n---------------\n"
newly_created_font=$(find -maxdepth 1 -name '*.[o,t]tf')
echo "newly_created_font = $newly_created_font"
patched_font_dir="${f%/*}/"
patched_font_dir="${patched_font_dir/unpatched-sample-fonts/patched-fonts}"
mv "$newly_created_font" $patched_font_dir

./font-patcher --fontawesome --pomicons -q -w "$f"
printf "\n---------------\n"
newly_created_font=$(find -maxdepth 1 -name '*.[o,t]tf')
echo "newly_created_font = $newly_created_font"
patched_font_dir="${f%/*}/"
patched_font_dir="${patched_font_dir/unpatched-sample-fonts/patched-fonts}"
mv "$newly_created_font" $patched_font_dir

./font-patcher --fontawesome --pomicons -q -s -w "$f"
printf "\n---------------\n"
newly_created_font=$(find -maxdepth 1 -name '*.[o,t]tf')
echo "newly_created_font = $newly_created_font"
patched_font_dir="${f%/*}/"
patched_font_dir="${patched_font_dir/unpatched-sample-fonts/patched-fonts}"
mv "$newly_created_font" $patched_font_dir

# octicons + pomicons variations:
./font-patcher --octicons --pomicons -q "$f"
printf "\n---------------\n"
newly_created_font=$(find -maxdepth 1 -name '*.[o,t]tf')
echo "newly_created_font = $newly_created_font"
patched_font_dir="${f%/*}/"
patched_font_dir="${patched_font_dir/unpatched-sample-fonts/patched-fonts}"
mv "$newly_created_font" $patched_font_dir

./font-patcher --octicons --pomicons -q -s "$f"
printf "\n---------------\n"
newly_created_font=$(find -maxdepth 1 -name '*.[o,t]tf')
echo "newly_created_font = $newly_created_font"
patched_font_dir="${f%/*}/"
patched_font_dir="${patched_font_dir/unpatched-sample-fonts/patched-fonts}"
mv "$newly_created_font" $patched_font_dir

./font-patcher --octicons --pomicons -q -w "$f"
printf "\n---------------\n"
newly_created_font=$(find -maxdepth 1 -name '*.[o,t]tf')
echo "newly_created_font = $newly_created_font"
patched_font_dir="${f%/*}/"
patched_font_dir="${patched_font_dir/unpatched-sample-fonts/patched-fonts}"
mv "$newly_created_font" $patched_font_dir
patch_font_batch "$f"

./font-patcher --octicons --pomicons -q -s -w "$f"
printf "\n---------------\n"
newly_created_font=$(find -maxdepth 1 -name '*.[o,t]tf')
echo "newly_created_font = $newly_created_font"
patched_font_dir="${f%/*}/"
patched_font_dir="${patched_font_dir/unpatched-sample-fonts/patched-fonts}"
mv "$newly_created_font" $patched_font_dir
# font awesome variations
patch_font_batch "$f" --fontawesome

# fontawesome + octicons + pomicons variations:
./font-patcher --fontawesome --octicons --pomicons -q "$f"
printf "\n---------------\n"
newly_created_font=$(find -maxdepth 1 -name '*.[o,t]tf')
echo "newly_created_font = $newly_created_font"
patched_font_dir="${f%/*}/"
patched_font_dir="${patched_font_dir/unpatched-sample-fonts/patched-fonts}"
mv "$newly_created_font" $patched_font_dir
# octicons variations:
patch_font_batch "$f" --octicons

./font-patcher --fontawesome --octicons --pomicons -q -s "$f"
printf "\n---------------\n"
newly_created_font=$(find -maxdepth 1 -name '*.[o,t]tf')
echo "newly_created_font = $newly_created_font"
patched_font_dir="${f%/*}/"
patched_font_dir="${patched_font_dir/unpatched-sample-fonts/patched-fonts}"
mv "$newly_created_font" $patched_font_dir
# pomicon variations:
patch_font_batch "$f" --pomicons

./font-patcher --fontawesome --octicons --pomicons -q -w "$f"
printf "\n---------------\n"
newly_created_font=$(find -maxdepth 1 -name '*.[o,t]tf')
echo "newly_created_font = $newly_created_font"
patched_font_dir="${f%/*}/"
patched_font_dir="${patched_font_dir/unpatched-sample-fonts/patched-fonts}"
mv "$newly_created_font" $patched_font_dir
# fontawesome + octicons variations:
patch_font_batch "$f" --fontawesome --octicons

./font-patcher --fontawesome --octicons --pomicons -q -s -w "$f"
printf "\n---------------\n"
newly_created_font=$(find -maxdepth 1 -name '*.[o,t]tf')
echo "newly_created_font = $newly_created_font"
patched_font_dir="${f%/*}/"
patched_font_dir="${patched_font_dir/unpatched-sample-fonts/patched-fonts}"
mv "$newly_created_font" $patched_font_dir
# fontawesome + pomicons variations:
patch_font_batch "$f" --fontawesome --pomicons

# octicons + pomicons variations:
patch_font_batch "$f" --octicons --pomicons

# fontawesome + octicons + pomicons variations:
patch_font_batch "$f" --fontawesome --octicons --pomicons

# un-comment to test this script (patch 1 font)
#break
# un-comment to test this script (patch 1 font)
#break
done


Expand Down

0 comments on commit bb4064d

Please sign in to comment.