Last active
October 30, 2022 06:11
-
-
Save fathergoose/e9c058014349f1cb588a0a1a057c740e to your computer and use it in GitHub Desktop.
A script to automate the installation of the latest neovim nightly tag
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
#!/usr/bin/env zsh | |
# Author: Alexander Ilseman | |
# Github: @fathergoose | |
# Date: 2022-10-18 | |
# Description: This script will update neovim to the latest nightly release | |
# System: macOS | |
# Check if neovim is running | |
if ps aux | awk '{print $11}' | grep -E '^nvim$' > /dev/null ; then | |
echo "Neovim is running. Please close it and try again." | |
exit 1 | |
fi | |
# Define colors | |
BOLD="\e[1m" | |
ITALIC="\e[3m" | |
UNDERLINE="\e[4m" | |
RESET="\e[0m" | |
RED="\e[31m" | |
GREEN="\e[32m" | |
# Define directories | |
LOCAL_DIR=$HOME/local | |
SRC_DIR=$LOCAL_DIR/src | |
NVIM_SRC=$SRC_DIR/neovim | |
NVIM_OUT=$LOCAL_DIR/neovim | |
NVIM_TMP=$LOCAL_DIR/tmp | |
# Create directories if they don't exist | |
if mkdir -p $SRC_DIR; then | |
echo "\n $GREEN Created $SRC_DIR $RESET \n" | |
fi | |
# Clean old source | |
if rm -rf $NVIM_SRC; then | |
echo "$BOLD \nRemoved old source files from $NVIM_SRC \n $RESET" | |
else | |
echo "$BOLD \nNo previous source to remove. Performing fresh install \n $RESET" | |
fi | |
# Clone latest | |
cd $SRC_DIR | |
echo "$BOLD \n cd $SRC_DIR \n $RESET" | |
git clone --depth 1 --branch nightly https://github.com/neovim/neovim.git | |
# Clean previous archive | |
rm $LOCAL_DIR/nvim.build-* &> /dev/null | |
# Check if there is a previously built version | |
if [[ -d $NVIM_OUT ]]; then | |
# Archive last build in case a rollback is needed | |
ZIP_PATH="$LOCAL_DIR/nvim.build-$(date '+%s').zip" | |
if zip -r $ZIP_PATH $NVIM_OUT; then | |
echo "$GREEN \n Archived previous build to $ZIP_PATH \n $RESET" | |
else | |
echo "$RED \nThere was a problem archiving the previous build \n $RESET" | |
# Allow user to back out if there was a problem archiving | |
# Just carry on if job is being run by cron | |
if [ -t 1 ]; then | |
read -r -q "OK?Continue installation? y/n " | |
if [[ $OK != y ]]; then | |
exit 1 | |
fi | |
fi | |
fi | |
# Ideally, we want to build the new version in a temporary directory | |
# and then move it to the final destination. | |
# However, I ain't no C guy. Cmake? More like Cmake me cry. | |
# Just play with it next time you're here. Get back to real work now. | |
rm -rf $NVIM_OUT | |
else | |
echo "$BOLD \nNo previous build fround at $NVIM_OUT \n $RESET" | |
fi | |
# Prepare for new build | |
mkdir $NVIM_OUT | |
cd $NVIM_SRC | |
# Build | |
make CMAKE_BUILD_TYPE=RelWithDebInfo CMAKE_INSTALL_PREFIX=$NVIM_OUT | |
make install | |
# Link executable to directory in $PATH | |
if [[ -L $LOCAL_DIR/bin/nvim ]]; then | |
echo "$BOLD ls -l $LOCAL_DIR/bin/nvim" | |
ls -l $LOCAL_DIR/bin/nvim | |
echo "$RESET" | |
else | |
if ln -s $NVIM_OUT/bin/nvim $LOCAL_DIR/bin/nvim &> /dev/null; then | |
echo "$GREEN \nLinked $NVIM_OUT/bin/nvim to $LOCAL_DIR/bin/nvim \n $RESET" | |
else | |
echo "$RED \nThere was a problem linking $NVIM_OUT/bin/nvim to $LOCAL_DIR/bin/nvim \n $RESET" | |
fi | |
fi | |
echo "$GREEN $BOLD \nNeovim is now installed at $NVIM_OUT \n $RESET" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment