#!/bin/bash

set -e

FONT_DIR="$HOME/.local/share/fonts"
TEMP_DIR=$(mktemp -d)

mkdir -p "$FONT_DIR"

pushd $TEMP_DIR
curl -s 'https://api.github.com/repos/be5invis/Iosevka/releases/latest' | \
  jq -r ".assets[] | .browser_download_url" | \
  grep PkgTTC-Iosevka | \
  xargs -n 1 curl -L -O --fail --silent --show-error

for f in *.zip; do
    unzip "$f"
done

mv *.ttc "$FONT_DIR/"
fc-cache -f -v "$FONT_DIR"

popd
rm -rf "$TEMP_DIR"

echo "Iosevka fonts have been installed."