Skip to content

Instantly share code, notes, and snippets.

@hunzo
Last active June 26, 2025 08:59
Show Gist options
  • Save hunzo/618983e51a9636ca84090722ecddee2f to your computer and use it in GitHub Desktop.
Save hunzo/618983e51a9636ca84090722ecddee2f to your computer and use it in GitHub Desktop.
script install neovim
#!/bin/bash
NVIM_VERSION="v0.11.2"
NVIM_FILE_NAME="nvim-linux-x86_64"
# Colors for output
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# --- Helper Functions ---
log_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
log_warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1" >&2
exit 1
}
# Function to check if a command exists
command_exists() {
type "$1" &>/dev/null
}
# Function to append content to .bashrc if not already present
append_to_bashrc() {
local content="$1"
local check_string="$2"
if ! grep -q "$check_string" "$HOME/.bashrc"; then
log_info "Adding configuration to ~/.bashrc..."
echo -e "\n$content" >>"$HOME/.bashrc"
else
log_info "Configuration for '$check_string' already exists in ~/.bashrc. Skipping."
fi
}
install_neovim() {
log_info "Starting Neovim installation ($NVIM_VERSION)..."
# Clean old Neovim configurations and binaries
log_info "Removing old Neovim configurations and binaries..."
rm -rf "$HOME/.config/nvim" \
"$HOME/.local/share/nvim" \
"$HOME/.local/state/nvim" \
"$HOME/.cache/nvim"
sudo rm -rf /usr/bin/nvim*
# Add Neovim as default editor to .bashrc
local nvim_editor_config=$(
cat <<'EOF'
# --- Neovim as Default Editor ---
export EDITOR=nvim
alias vim=nvim
set -o vi
# --- End Neovim Default Editor ---
EOF
)
append_to_bashrc "$nvim_editor_config" "export EDITOR=nvim"
# Download Neovim
local nvim_tar_file="${NVIM_FILE_NAME}.tar.gz"
log_info "Downloading Neovim $NVIM_VERSION..."
if ! curl -fsSL "https://github.com/neovim/neovim/releases/download/${NVIM_VERSION}/${nvim_tar_file}" -o "${nvim_tar_file}"; then
log_error "Failed to download Neovim. Please check the version or URL."
fi
# Install Neovim
log_info "Extracting and linking Neovim to /usr/bin..."
if ! sudo tar -xzf "${nvim_tar_file}" -C /usr/bin/; then
log_error "Failed to extract Neovim. Check permissions or file integrity."
fi
if ! sudo ln -sf "/usr/bin/${NVIM_FILE_NAME}/bin/nvim" /usr/bin/nvim; then
log_error "Failed to create symlink for Neovim. Check permissions."
fi
# Clean up downloaded tarball
rm -f "${nvim_tar_file}"
log_info "Neovim installation completed."
}
main() {
log_info "Starting overall development environment setup..."
# Check for root privileges early
if [ "$EUID" -eq 0 ]; then
log_error "This script should NOT be run as root. Please run as a normal user."
fi
# Install individual components
install_neovim
log_info "All setup steps completed successfully!"
log_info "Please remember to run 'source ~/.bashrc' or restart your terminal for changes to take effect."
}
# Execute the main function
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment