#!/bin/sh
set -eu

SPELL_DIR="$HOME/.local/share/nvim/site/spell"
mkdir -p "$SPELL_DIR"

cd "$SPELL_DIR"

die() {
  printf 'Fehler: %s\n' "$*" >&2
  exit 1
}

have() {
  command -v "$1" >/dev/null 2>&1
}

download() {
  url="$1"
  file=$(basename "$url")

  if [ -f "$file" ]; then
    printf "✓ %-32s vorhanden\n" "$file"
    return
  fi

  printf "→ Lade %s herunter\n" "$file"
  if have wget; then
    wget -q --show-progress "$url"
  elif have curl; then
    curl -fLO "$url"
  else
    die "weder wget noch curl gefunden"
  fi
}

main() {
  download "https://ftp.nluug.nl/pub/vim/runtime/spell/de.utf-8.spl"
  download "https://ftp.nluug.nl/pub/vim/runtime/spell/de.utf-8.sug"

  printf "\nWörterbücher für Neovim installiert!\n"
}

main "$@"
