#!/bin/sh
# lazyvim-setup - install the official LazyVim starter config for this user
#
# Run as yourself, not root - it acts on your own $HOME.
set -eu

[ "$(id -u)" != 0 ] || {
	echo "lazyvim-setup: run this as your own user, not root - it sets up" >&2
	echo "  nvim for whoever runs it, and root's \$HOME is not that." >&2
	exit 1
}
command -v git >/dev/null 2>&1 || { echo "lazyvim-setup: git is required" >&2; exit 1; }

ts=$(date '+%Y%m%d-%H%M%S')
backup() {
	[ -e "$1" ] || return 0
	mv "$1" "$1.bak-$ts"
	echo "  backed up $1 -> $1.bak-$ts"
}

# Required.
backup "$HOME/.config/nvim"
# Optional, but recommended by LazyVim's own install docs - stale state or
# plugin caches from a previous config can otherwise leak into this one.
backup "$HOME/.local/share/nvim"
backup "$HOME/.local/state/nvim"
backup "$HOME/.cache/nvim"

git clone https://github.com/LazyVim/starter "$HOME/.config/nvim"
rm -rf "$HOME/.config/nvim/.git"

echo "LazyVim installed. Run nvim to finish the plugin sync on first start."
