#!/usr/bin/env bash

set -euo pipefail

if ! command -v nvim >/dev/null 2>&1; then
  echo "nvim is required" >&2
  exit 1
fi

if ! command -v tree-sitter >/dev/null 2>&1; then
  echo "tree-sitter CLI is required for nvim-treesitter main-branch parser installs" >&2
  exit 1
fi

if ! command -v curl >/dev/null 2>&1; then
  echo "curl is required" >&2
  exit 1
fi

if ! command -v tar >/dev/null 2>&1; then
  echo "tar is required" >&2
  exit 1
fi

INSTALL_EXPR="require('nvim-treesitter').install({'c','query','vimdoc','vim','bash','go','css','python','html','javascript','json','lua','rust','typescript'}):wait(300000)"

XDG_STATE_HOME="${XDG_STATE_HOME:-/tmp/nvim-state-bootstrap}" \
  nvim --headless \
  "+lua ${INSTALL_EXPR}" \
  "+qa"
