Last active
January 26, 2024 00:13
-
-
Save MohamedElashri/e061be8e8e27df8b5344eb377967162f to your computer and use it in GitHub Desktop.
Use nvim as IDE with NvChad
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Check if Neovim is installed | |
if ! command -v nvim &> /dev/null | |
then | |
read -p "Neovim is not installed. Do you have root access to install it globally? (y/n) " root_choice | |
case "$root_choice" in | |
y|Y ) | |
# OS-specific Neovim installation | |
if [[ -x "$(command -v apt-get)" ]]; then | |
sudo add-apt-repository ppa:neovim-ppa/unstable -y | |
sudo apt-get update | |
sudo apt-get install neovim -y | |
elif [[ -x "$(command -v yum)" ]]; then | |
sudo yum install neovim | |
elif [[ -x "$(command -v dnf)" ]]; then | |
sudo dnf install neovim | |
else | |
echo "Unsupported OS for automatic Neovim installation" | |
exit 1 | |
fi | |
;; | |
n|N ) | |
read -p "Do you want to install it locally? (y/n) " local_choice | |
case "$local_choice" in | |
y|Y ) | |
# Handling the existing Neovim directory | |
if [ -d /tmp/neovim ]; then | |
if [ -d /tmp/neovim/.git ]; then | |
echo "Updating existing Neovim repository in /tmp/neovim..." | |
git -C /tmp/neovim pull | |
else | |
echo "Removing non-git neovim directory and cloning afresh..." | |
rm -rf /tmp/neovim | |
git clone https://github.com/neovim/neovim.git /tmp/neovim | |
fi | |
else | |
git clone https://github.com/neovim/neovim.git /tmp/neovim | |
fi | |
cd /tmp/neovim | |
# Configure the build with local prefix | |
make CMAKE_BUILD_TYPE=RelWithDebInfo | |
cmake -S . -B build -DCMAKE_INSTALL_PREFIX=$HOME/.local -G Ninja | |
# Build and install using Ninja | |
ninja -C build | |
ninja -C build install | |
# Add local bin to PATH if not already done | |
if [[ ":$PATH:" != *":$HOME/.local/bin:"* ]]; then | |
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc | |
source ~/.bashrc | |
fi | |
;; | |
n|N ) | |
echo "Neovim is required for nvChad. Please install Neovim and run the script again." | |
exit 1 | |
;; | |
* ) | |
echo "Invalid choice. Please respond with 'y' or 'n'." | |
exit 1 | |
;; | |
esac | |
;; | |
* ) | |
echo "Invalid choice. Please respond with 'y' or 'n'." | |
exit 1 | |
;; | |
esac | |
else | |
# Check Neovim version | |
installed_version=$(nvim --version | head -n 1 | awk '{print $2}') | |
required_version="0.8.0" | |
if [ "$(printf '%s\n' "$required_version" "$installed_version" | sort -V | head -n1)" != "$required_version" ]; then | |
echo "Installed Neovim version ($installed_version) is less than the required version ($required_version)." | |
echo "Please update Neovim to at least version $required_version." | |
exit 1 | |
fi | |
fi | |
# Check if nvChad is already installed | |
if [ -d ~/.config/nvim/NvChad ]; then | |
echo "nvChad is already installed." | |
else | |
# Create a temporary directory for cloning | |
temp_dir=$(mktemp -d) | |
# Clone nvChad into the temporary directory | |
git clone https://github.com/NvChad/NvChad "$temp_dir/NvChad" --depth 1 | |
# Check if the clone was successful | |
if [ -d "$temp_dir/NvChad" ]; then | |
echo "Moving files to ~/.config/nvim..." | |
# Using rsync to move and merge directories | |
rsync -av --exclude='.git' "$temp_dir/NvChad/" ~/.config/nvim/ | |
# Remove the temporary directory | |
rm -rf "$temp_dir" | |
# Launch nvim | |
nvim | |
else | |
echo "Failed to clone NvChad repository." | |
exit 1 | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment