Last active
December 21, 2023 19:02
-
-
Save ecosse3/ab58a8577d8c69dccdf03304b720e1c8 to your computer and use it in GitHub Desktop.
Update Neovim Nightly from latest github release
This file contains hidden or 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 | |
# Colors definitions | |
RED='\033[0;31m' | |
GREEN='\033[0;32m' | |
NC='\033[0m' # No Color | |
BOLD=$(tput bold) | |
NORMAL=$(tput sgr0) | |
# Check if necessary applications are installed | |
if ! [ -x "$(command -v wget)" ]; then | |
printf "\n${RED}wget not found in path. Please install it to continue!${NC}\n" | |
exit | |
fi | |
if ! [ -x "$(command -v curl)" ]; then | |
printf "\n${RED}curl not found in path. Please install it to continue!${NC}\n" | |
exit | |
fi | |
if ! [ -x "$(command -v xmllint)" ]; then | |
printf "\n${RED}xmllint not found in path. Please install it to continue!${NC}\n" | |
exit | |
fi | |
if ! [ -x "$(command -v datediff)" ]; then | |
printf "\n${RED}dateutils not found in path. Please install it to continue!${NC}\n" | |
exit | |
fi | |
# Get newest Neovim Nightly info | |
wget https://github.com/neovim/neovim/releases/tag/nightly -q -O - > /tmp/nvim28dce75c-4317-4006-a103-8069d573e2b2 | |
RESPONSE=$(wget https://github.com/neovim/neovim/releases/tag/nightly --save-headers -O - 2>&1) | |
if [[ "$RESPONSE" =~ 404\ Not\ Found ]]; then | |
printf "${RED}Couldn't fetch newest Neovim Nighly info. Aborting...${NC}\n" | |
exit | |
fi | |
# Variables | |
SHOW_PROMPT=0 | |
CURR_NVIM_VER=$(nvim --version | head -n 1) | |
NEW_NVIM_VER=$(xmllint --html --xpath "//pre//code/node()" /tmp/nvim28dce75c-4317-4006-a103-8069d573e2b2 2>/dev/null | grep NVIM) | |
CURR_DATETIME_ISO=$(date --iso-8601=ns) | |
NEW_NVIM_VER_RELEASE_DATETIME_ISO=$(xmllint --html --xpath "string(//relative-time/@datetime)" /tmp/nvim28dce75c-4317-4006-a103-8069d573e2b2 2>/dev/null) | |
LAST_RELEASE_DATETIME_DIFF=$(datediff ${NEW_NVIM_VER_RELEASE_DATETIME_ISO} ${CURR_DATETIME_ISO} -f "%H hours %M minutes ago") | |
# Check if Neovim Nightly exists in repo | |
if [[ "$NEW_NVIM_VER" == "" ]]; then | |
printf "\n${RED}Couldn't fetch latest Neovim Nightly version from github repo! Check if it exists. Aborting...${NC}\n" | |
exit | |
fi | |
# Check if the current neovim version is the latest | |
if [[ "$CURR_NVIM_VER" == "$NEW_NVIM_VER" ]]; then | |
printf "\n${RED}No new version of ${BOLD}Neovim Nightly${NORMAL}${RED} found!\n${NC}Last release: ${LAST_RELEASE_DATETIME_DIFF}\nAborting...\n" | |
exit | |
fi | |
# If a newer version of Neovim Nightly found show prompt | |
if [[ CURR_NVIM_VER != NEW_NVIM_VER ]]; then | |
printf "\n${GREEN}New ${BOLD}Neovim Nightly${NORMAL}${GREEN} version found!${NC}\n${CURR_NVIM_VER} -> ${BOLD}${NEW_NVIM_VER}${NORMAL}\nReleased: ${LAST_RELEASE_DATETIME_DIFF}\n\n" | |
SHOW_PROMPT=1 | |
fi | |
# Update function | |
update_neovim() { | |
printf "${RED}Updating Neovim Nightly...${NC}\n" | |
HTTPS_URL="https://github.com/neovim/neovim/releases/download/nightly/nvim.appimage" | |
CURL_CMD="curl -L -w http_code=%{http_code}" | |
CURL_OUTPUT=`${CURL_CMD} ${HTTPS_URL} -o /tmp/nvim` | |
HTTP_CODE=$(echo "${CURL_OUTPUT}" | sed -e 's/.*\http_code=//') | |
ERROR_MESSAGE=$(echo "${CURL_OUTPUT}" | sed -e 's/http_code.*//') | |
if [[ ${HTTP_CODE} == 200 ]]; then | |
chmod +x /tmp/nvim; | |
sudo cp /tmp/nvim /usr/local/bin; | |
sudo mv /tmp/nvim /usr/bin; | |
printf "${GREEN}Neovim Nightly has been updated successfully!${NC}\n" | |
else | |
printf "${RED}Neovim Nightly has NOT been updated! ERROR: ${ERROR_MESSAGE}${NC}\n" | |
fi | |
} | |
rm /tmp/nvim28dce75c-4317-4006-a103-8069d573e2b2 | |
while [ $SHOW_PROMPT -gt 0 ]; do | |
read -p "Do you wish to update neovim? [yes/no] " yn | |
case $yn in | |
[Yy]* ) update_neovim; break;; | |
[Nn]* ) exit;; | |
* ) echo "Please answer yes or no.";; | |
esac | |
done |
Does this script overwrites my current
init.vim
config?
No, it doesn't. It just updates neovim in /usr/local/bin.
Can i get neovim nightly with this? Or this for update only?
- Doesn't follow github redirects
- Doesn't save curl output to /tmp/nvim
- http_status check is wrong
Fix - change these lines as below:
Line 56-57:
CURL_CMD="curl -L -w http_code=%{http_code}"
CURL_OUTPUT=`${CURL_CMD} ${HTTPS_URL} -o /tmp/nvim`
Line 59:
if [ ${HTTP_CODE} -eq 200 ]; then
@qqhgs yes
@qqhgs yes
@itsfarseen, thank you! Updated gist and added few more checks.
What version dateuqils do you have, I keep getting this error.
date: illegal option -- -
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
[-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
ddiff: Error: reference DATE must be specified
FYI I had to apply the following link in order to use this:
sudo ln -s /usr/bin/dateutils.ddiff /usr/local/bin/datediff
For mac use
CURR_DATETIME_ISO=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does this script overwrites my current
init.vim
config?