#!/bin/bash

VERSION=$1

rm -f nerd-fonts-noto-*.tar.?z*

mkdir nerd-fonts-noto-$VERSION
cd nerd-fonts-noto-$VERSION

wget --content-disposition https://github.com/ryanoasis/nerd-fonts/releases/download/v$VERSION/Noto.zip

unzip Noto.zip
rm -f Noto.zip

rm -f *"Windows Compatible.ttf"

# Remove spaces from file names
for f in *\ *; do mv "$f" "${f// /}"; done

# Remove Mono versions of non-Mono fonts and non-Mono versions of Mono fonts
rm -f NotoSerif*Mono.ttf
for f in $(ls -1 NotoSansMono* | grep -v "Mono.ttf"); do
  rm -f "$f"
done
for f in $(ls -1 NotoMono* | grep -v "Mono.ttf"); do
  rm -f "$f"
done
for f in $(ls -1 NotoSans* | grep -v "NotoSansMono" | grep "Mono.ttf"); do
  rm -f "$f"
done

cd ..

tar --exclude-vcs -cf nerd-fonts-noto-$VERSION.tar nerd-fonts-noto-$VERSION
plzip -9 nerd-fonts-noto-$VERSION.tar

rm -rf nerd-fonts-noto-$VERSION
