#!/bin/bash set -euo pipefail REPO="git@gitea.hptrow.me:pt/nvchad.git" BRANCH="customize" NVIM_CONFIG="$HOME/.config/nvim" SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" source "$SCRIPT_DIR/_lib.sh" echo "============================================" echo "NvChad Configuration Installation Script" echo "============================================" echo "" # Check prerequisites if ! command -v nvim &> /dev/null; then echo "Error: Neovim is not installed or not in PATH" >&2 echo "Please run ./install_neovim.sh first" >&2 exit 1 fi if ! command -v git &> /dev/null; then echo "Error: Git is not installed" >&2 exit 1 fi # Verify Neovim version NVIM_VERSION=$(nvim --version | head -n1 | grep -oP 'v\K[0-9]+\.[0-9]+' || echo "0.0") REQUIRED_VERSION="0.9" if [ "$(printf '%s\n' "$REQUIRED_VERSION" "$NVIM_VERSION" | sort -V | head -n1)" != "$REQUIRED_VERSION" ]; then echo "Error: Neovim version $NVIM_VERSION is too old (need 0.9.5+)" >&2 exit 1 fi echo "Neovim version: $(nvim --version | head -n1)" echo "" # If already installed and pointing at the right remote, just pull if [ -d "$NVIM_CONFIG/.git" ]; then REMOTE_NAME="" if git -C "$NVIM_CONFIG" remote get-url hptrow &>/dev/null; then REMOTE_NAME="hptrow" elif git -C "$NVIM_CONFIG" remote get-url origin &>/dev/null; then REMOTE_NAME="origin" fi EXISTING_REMOTE=$(git -C "$NVIM_CONFIG" remote get-url "$REMOTE_NAME" 2>/dev/null || echo "") if [ "$EXISTING_REMOTE" = "$REPO" ]; then echo "NvChad config already installed — pulling latest..." stashed=false if ! git -C "$NVIM_CONFIG" diff --quiet || ! git -C "$NVIM_CONFIG" diff --cached --quiet; then git -C "$NVIM_CONFIG" stash stashed=true fi git -C "$NVIM_CONFIG" pull "$REMOTE_NAME" "$BRANCH" $stashed && git -C "$NVIM_CONFIG" stash pop || true deploy_nvim echo "Done." exit 0 fi fi echo "This script will:" echo " - Backup existing ~/.config/nvim to ~/.config/nvim.backup (if exists)" echo " - Clone your NvChad config from $REPO ($BRANCH branch)" echo " - Deploy lua modules from dotfiles/nvim/" echo " - Launch nvim to auto-install lazy.nvim and all plugins" echo "" echo "Prerequisites:" echo " - SSH key must be set up for gitea.hptrow.me" echo "" read -p "Continue with installation? (y/N) " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then echo "Installation cancelled." exit 0 fi echo "" echo "Starting installation..." echo "" # Backup existing config if [ -d "$NVIM_CONFIG" ]; then echo "Backing up existing ~/.config/nvim to ~/.config/nvim.backup" [ -d "$NVIM_CONFIG.backup" ] && rm -rf "$NVIM_CONFIG.backup" mv "$NVIM_CONFIG" "$NVIM_CONFIG.backup" fi # Clone the config echo "Cloning NvChad config from gitea ($BRANCH branch)..." set -x git clone -b "$BRANCH" "$REPO" "$NVIM_CONFIG" set +x [ -d "$NVIM_CONFIG" ] || { echo "Error: Failed to clone config" >&2; exit 1; } echo "" echo "Config cloned successfully!" echo "" deploy_nvim echo "" echo "============================================" echo "First Launch Setup" echo "============================================" echo "" echo "Neovim will now launch and automatically:" echo " 1. Bootstrap lazy.nvim plugin manager" echo " 2. Install NvChad (as a plugin)" echo " 3. Install all configured plugins" echo "" echo "This may take a few minutes on first run." echo "After installation completes, close nvim with :q" echo "" read -p "Press Enter to launch nvim and complete setup..." -r echo "" nvim +q echo "" echo "============================================" echo "Installation Complete!" echo "============================================" echo "" echo "Your NvChad configuration is installed at: $NVIM_CONFIG" echo "" echo "Key customizations in this config:" echo " - Theme: vscode_dark" echo " - Tab width: 4 spaces" echo " - Obsidian.nvim integration" echo " - SQL development tools (pg_format, sqlfluff)" echo " - Mason for installing formatters" echo " - Custom keybindings: g+w (format), gb (blame), more in lua/mappings.lua" echo "" echo "Next time you launch nvim, everything will be ready!" echo "" [ -d "$NVIM_CONFIG.backup" ] && echo "Note: Your old config was backed up to $NVIM_CONFIG.backup" echo "============================================"