bake_in_features.sh 853 B

12345678910111213141516171819202122232425262728
  1. #!/bin/bash
  2. set -o errexit -o nounset -o pipefail
  3. cd "$(dirname "$0")/.."
  4. glyphs_file=${FIRACODE_GLYPHS_FILE:-"FiraCode.glyphs"}
  5. code_blocks=()
  6. for feat in "$@"; do
  7. file="features/${feat}.fea"
  8. if [ ! -f "${file}" ]; then
  9. echo "Error: No file for feature ${feat} found!" >&2
  10. exit 1
  11. fi
  12. # don't grab the "lookup" surroundings or comments or whitespace lines
  13. code="$(grep -v '^[[:space:]]*lookup\|^[[:space:]]*}\|^[[:space:]]*#\|^[[:space:]]*$' "${file}")" \
  14. || { echo "Error: No code for feature ${feat} found!" >&2; exit 1; }
  15. code_blocks+=("$(tr '\n' ' ' <<< "${code}")")
  16. done
  17. # code block is one line above name declaration
  18. linenum=$(sed -n "/name = calt;/=" "${glyphs_file}")
  19. linenum=$((linenum - 1))
  20. # replace end of line (";) with code on specified line number
  21. sed -i -e "${linenum}s@\";\$@\n${code_blocks[*]}\";@" "${glyphs_file}"