diff --git a/install_nvchad.sh b/install_nvchad.sh index 00372e5..d19e8de 100755 --- a/install_nvchad.sh +++ b/install_nvchad.sh @@ -1,30 +1,29 @@ #!/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)" + +deploy_nvim_modules() { + local src_dir="$SCRIPT_DIR/dotfiles/nvim" + [[ -d "$src_dir" ]] || return 0 + [[ -d "$NVIM_CONFIG/lua" ]] || return 0 + echo "Deploying nvim lua modules..." + for mod in "$src_dir"/*.lua; do + [[ -f "$mod" ]] || continue + local target="$NVIM_CONFIG/lua/$(basename "$mod")" + [[ -e "$target" ]] && mv "$target" "${target}.backup" + ln -s "$mod" "$target" + echo " linked: $(basename "$mod")" + done +} + echo "============================================" echo "NvChad Configuration Installation Script" echo "============================================" echo "" -echo "This script will:" -echo " - Backup existing ~/.config/nvim to ~/.config/nvim.backup (if exists)" -echo " - Clone your NvChad config from git@gitea.hptrow.me:pt/nvchad.git (customize branch)" -echo " - Launch nvim to auto-install lazy.nvim and all plugins" -echo "" -echo "Prerequisites:" -echo " - Neovim 0.9.5+ must be installed (run ./install_neovim.sh if needed)" -echo " - Git must be installed" -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 "" # Check prerequisites if ! command -v nvim &> /dev/null; then @@ -49,28 +48,59 @@ fi echo "Neovim version: $(nvim --version | head -n1)" echo "" -# Backup existing config if it exists -if [ -d ~/.config/nvim ]; then - echo "Backing up existing ~/.config/nvim to ~/.config/nvim.backup" - if [ -d ~/.config/nvim.backup ]; then - rm -rf ~/.config/nvim.backup +# If already installed and pointing at the right remote, just pull +if [ -d "$NVIM_CONFIG/.git" ]; then + EXISTING_REMOTE=$(git -C "$NVIM_CONFIG" remote get-url hptrow 2>/dev/null || git -C "$NVIM_CONFIG" remote get-url origin 2>/dev/null || echo "") + if [ "$EXISTING_REMOTE" = "$REPO" ]; then + echo "NvChad config already installed — pulling latest..." + git -C "$NVIM_CONFIG" pull hptrow "$BRANCH" + deploy_nvim_modules + echo "Done." + exit 0 fi - mv ~/.config/nvim ~/.config/nvim.backup fi -# Clone the config -echo "Cloning NvChad config from gitea (customize branch)..." -set -x -git clone -b customize git@gitea.hptrow.me:pt/nvchad.git ~/.config/nvim -set +x - -if [ ! -d ~/.config/nvim ]; then - echo "Error: Failed to clone config" >&2 - exit 1 +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_modules + echo "" echo "============================================" echo "First Launch Setup" @@ -87,7 +117,6 @@ echo "" read -p "Press Enter to launch nvim and complete setup..." -r echo "" -# Launch nvim to trigger plugin installation nvim +q echo "" @@ -95,7 +124,7 @@ echo "============================================" echo "Installation Complete!" echo "============================================" echo "" -echo "Your NvChad configuration is installed at: ~/.config/nvim" +echo "Your NvChad configuration is installed at: $NVIM_CONFIG" echo "" echo "Key customizations in this config:" echo " - Theme: vscode_dark" @@ -107,7 +136,5 @@ echo " - Custom keybindings: g+w (format), gb (blame), more in lua/mapp echo "" echo "Next time you launch nvim, everything will be ready!" echo "" -if [ -d ~/.config/nvim.backup ]; then - echo "Note: Your old config was backed up to ~/.config/nvim.backup" -fi +[ -d "$NVIM_CONFIG.backup" ] && echo "Note: Your old config was backed up to $NVIM_CONFIG.backup" echo "============================================"