setup_env/install_neovim.sh
Paul Trowbridge d3bf321341 pin neovim to v0.11.3
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-10 04:40:38 -04:00

93 lines
2.7 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
echo "============================================"
echo "Neovim v0.11.3 Installation Script"
echo "============================================"
echo ""
echo "This script will run the following commands with sudo:"
echo " - apt-get update (if curl not installed)"
echo " - apt-get install -y curl (if needed)"
echo " - rm -rf /opt/nvim-linux64 or /opt/nvim-linux-x86_64 (if old installation exists)"
echo " - tar -C /opt -xzf nvim-linux-x86_64.tar.gz"
echo " - add nvim to PATH in ~/setup_env/dotfiles/.bashrc_paths (if not already there)"
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 (commands will be shown as they run)..."
echo ""
# Enable command tracing
set -x
# Check for required tools
if ! command -v curl &> /dev/null; then
sudo apt-get update
sudo apt-get install -y curl
fi
# Disable tracing temporarily for cleaner download messages
set +x
# Download latest Neovim
echo "Downloading Neovim..."
TEMP_DIR=$(mktemp -d)
cd "$TEMP_DIR"
if ! curl -fsSL -o nvim-linux-x86_64.tar.gz https://github.com/neovim/neovim/releases/download/v0.11.3/nvim-linux-x86_64.tar.gz; then
echo "Error: Failed to download Neovim" >&2
rm -rf "$TEMP_DIR"
exit 1
fi
echo "Download complete."
set -x
# Remove old installation if it exists (either naming convention)
if [ -d /opt/nvim-linux64 ]; then
sudo rm -rf /opt/nvim-linux64
fi
if [ -d /opt/nvim-linux-x86_64 ]; then
sudo rm -rf /opt/nvim-linux-x86_64
fi
# Extract to /opt
sudo tar -C /opt -xzf nvim-linux-x86_64.tar.gz
set +x
# Clean up
cd - > /dev/null
rm -rf "$TEMP_DIR"
echo ""
echo "============================================"
# Verify installation
if [ -x /opt/nvim-linux-x86_64/bin/nvim ]; then
echo "Neovim installed successfully!"
/opt/nvim-linux-x86_64/bin/nvim --version | head -n1
echo ""
echo "Neovim is installed at: /opt/nvim-linux-x86_64/bin/nvim"
# Add to .bashrc_paths if not already there
BASHRC_PATHS="$HOME/setup_env/dotfiles/.bashrc_paths"
NVIM_PATH_LINE='[ -d /opt/nvim-linux-x86_64/bin ] && export PATH="/opt/nvim-linux-x86_64/bin:$PATH"'
if [ -f "$BASHRC_PATHS" ] && ! grep -qF "nvim-linux-x86_64" "$BASHRC_PATHS"; then
echo "" >> "$BASHRC_PATHS"
echo "# Neovim (installed by install_neovim.sh)" >> "$BASHRC_PATHS"
echo "$NVIM_PATH_LINE" >> "$BASHRC_PATHS"
echo "Added nvim to PATH in $BASHRC_PATHS"
echo "Run 'source ~/.bashrc' to apply."
fi
else
echo "Error: Neovim installation failed" >&2
exit 1
fi
echo "============================================"